Notes

What can I do with the DOM? (Examples)

Edit on GitHub

JavaScript

You can access elements and nodes.

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

You can add things to the document

1document.createElement()
2document.createAttribute() // creates and returns an attribute node
3document.appendChild()
4document.writeln(line) // writes a string of text followed by newline  
1let p = document.createElement('p')
2
3p.innerText = "This is text inside the paragraph element you just created. Hola!"
4
5document.body.appendChild(p)