Selecting DOM elements

Functions for accessing elements by class, id and other selectors.


Select DOM elements by CSS selector

querySelectorAll - a CSS selector method like the one provided by jQuery.

jQuery: $(selector), $(selector, context)

Select elements by class name

getElementsByClassName - a fast way of selecting DOM elements by class name in modern browsers. Does not work in IE 8 and below.

jQuery: $('.foo')

Select elements by tag name

getElementsByTagName - a fast and cross browser safe way for selecting DOM elements by tag name, e.g. "div", "a", "span", etc.

jQuery: $('div')

Select an element by ID

getElementById - a fast and cross browser safe way for selecting DOM elements.

jQuery: $('#foo')