Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Selecting DOM elements

Generally speaking there are many different ways to select elements from an HTML document. We use these functions:

document.body  // returns the whole body element of the html document

document.getElementById('unique') // returns the element with the id set to 'unique'

document.getElementsByTagName('H3') // returns an array with all h3 elements

document.getElementsByClassName('bigSize')  // returns an array with this class elements

document.querySelector('p.intro') // CSS selector type. Returns the first element that is a p and has a class 'intro'

document.querySelectorAll('div img') // returns an array with images that lie inside a div

 

Find a full list here!