iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML DOM Reference

The HTML DOM exposes a tree of nodes, each with a typed interface. Here are the ones you'll touch most.

The roots

TypeNotable members
DocumentquerySelector, querySelectorAll, getElementById, createElement, documentElement, head, body, title, activeElement, cookie, readyState
WindowinnerWidth, scrollTo, matchMedia, requestAnimationFrame, localStorage, history, location, navigator, crypto

Element family

TypeNotable members
NodenodeType, nodeName, parentNode, childNodes, appendChild, removeChild
ElementtagName, id, className, classList, attributes, dataset, closest, matches, remove, append, prepend, before, after
HTMLElementstyle, innerText, title, hidden, focus, blur, click
HTMLInputElementvalue, checked, files, validity, setCustomValidity
HTMLFormElementelements, checkValidity, reportValidity, submit, reset
HTMLImageElement / HTMLVideoElementsrc, naturalWidth, play, pause, currentTime

Events

TypeNotable members
Eventtype, target, currentTarget, preventDefault, stopPropagation, defaultPrevented
MouseEventclientX, clientY, button, shiftKey
KeyboardEventkey, code, ctrlKey, repeat
InputEventdata, inputType
PointerEventpointerType, pressure, tiltX/Y
FocusEvent / SubmitEvent / WheelEventSpecialised events.

Collections

TypeNotes
NodeListStatic (querySelectorAll) or live (childNodes). Supports forEach.
HTMLCollectionAlways live. children, forms, images.
DOMTokenListclassListadd, remove, toggle, contains.
Tip: The complete DOM has hundreds of interfaces. The "MDN DOM Interfaces" page is the canonical map — bookmark it and skim before reaching for a polyfill.

Example

Example
<!DOCTYPE html>
<html>
<body>

<p id="out"></p>

<script>
document.getElementById("out").textContent = "Hello from HTML DOM Reference!";
</script>

</body>
</html>
Try it Yourself »

Exercise

Add a CSS class with the modern API.

el. .add('active');

Test yourself

Q1. `classList` is a…
Q2. `HTMLCollection` is…
Q3. Modern remove call on an element is…

Discussion

Loading…