Coggle requires JavaScript to display documents.
... document.querySelector('button');
{ "compilerOptions": { "lib": [ "DOM", "ES2019" ], ... } }
Math
document
target
const btn = document.getElementById("submit");
btn
HTMLElement | null
HTMLElement
btn.addEventListener('click', () => {...});
'btn' is possibly 'null'
?.
null
undefined
.
btn?.addEventListener('click', () => {...});
!
const btn = document.getElementById("submit")!;
index.html
<input type="text" id="user-input">
userInputElement.value = 'Hi there!';
Property 'value' does not exist on type 'HTMLElement'
HTMLInputElement
const userInputElement = <HTMLInputElement>document.getElementById('user-input')!;
React
as
const userInputElement = document.getElementById('user-input')! as HTMLInputElement; userInputElement.value = 'Hi there!';
const userInputElement = document.getElementById('user-input')!;