Scripting Documents
Selecting Doucuments Elements
Selecting Elements By ID
var section1 = document.getElementById("section1");
Selecting Elements By type
var spans = document.getElementsByTagName("span");
Selecting Elements by CSS class
var warning s= document.getElementsByClassName("warning");
Selecting Elements by Name
Selecting Elements with CSS selectors
p[lang="fr"], #log>span
The key to this API is the Document method querySelectorAll(). It takes a single string argument containing a CSS selector and returns a NodeList that represents all elements in the document that match the selector.
the document object also defines querySelector(), which is like querySelectorAll(), but returns only the first (in document order) match- ing element or null if there is no matching element. Documents As Trees of Nodes
- parentNode
- childNodes
- firstChild, lastChild
- nextSibling, previousSibling
- nodeType, Document 9, Element 1, Text 3
- nodeValue
- nodeName
Documents As Trees of Elements
- Children
- firstElementChild, lastElementChild
- nextElementSibling, previousElementSibling
- childElementCount