TASIOMIND.DEV — OPERATIONAL▸▸▸FULL STACK DEVELOPER @ GWQ SERVICEPLUS AG▸▸▸FOUNDER — K8SGPT.AI▸▸▸OPEN SOURCE: ACTIVE▸▸▸DISTRIBUTED SYSTEMS / KUBERNETES / AI▸▸▸RUST + GO + PYTHON▸▸▸FIELD TESTED / STATUS — NOMINAL▸▸▸LOCATION: EUROPE/BERLIN▸▸▸TASIOMIND.DEV — OPERATIONAL▸▸▸FULL STACK DEVELOPER @ GWQ SERVICEPLUS AG▸▸▸FOUNDER — K8SGPT.AI▸▸▸OPEN SOURCE: ACTIVE▸▸▸DISTRIBUTED SYSTEMS / KUBERNETES / AI▸▸▸RUST + GO + PYTHON▸▸▸FIELD TESTED / STATUS — NOMINAL▸▸▸LOCATION: EUROPE/BERLIN▸▸▸

What can I do with the DOM? (Examples)

July 14, 2018

You can access elements and nodes.

code
document.getElementById(); // returns an element by it's ID
document.getElementsByClassName(); // returns a live HTMLCollection (array-like object)
document.getElementsByTagName(); // returns a live HTMLCollection
document.getElementsByTagNameNS(); // returns a live NodeList
document.querySelector(); // returns the **first** element, takes a CSS selector (`.class`, `#id`, `input[type="text"]`) as argument
document.querySelectorAll(); // returns a non-live NodeList of all elements
document.getElementsByName(); // returns a live NodeList

You can add things to the document

code
document.createElement();
document.createAttribute(); // creates and returns an attribute node
document.appendChild();
document.writeln(line); // writes a string of text followed by newline
code
let p = document.createElement("p");

p.innerText = "This is text inside the paragraph element you just created. Hola!";

document.body.appendChild(p);