Professional Documents
Culture Documents
Summary Node Query Method
Summary Node Query Method
Here's a summary of the various methods you got to reach out to DOM elements (note: you can
only query for element nodes).
Besides the below query methods, you also got these special properties on the document object
to select parts of the document:
---
QUERY METHODS
---
1. document.querySelector(<CSS selector>);
1. document.getElementById(<ID>);
Takes an ID (without # , just the id name) and returns the element that has this id. Since the same
ID shouldn't occur more than once on your page, it'll always return exactly that one element.
Returns null if no element with the specified ID could be found.
1. document.querySelectorAll(<CSS selector>);
Takes a CSS class g (e.g. 'some-class' ) and returns a live HTMLCollection of matched
elements in your DOM. Returns an empty HTMLCollection if not matching elements were
found.
1. document.getElementsByTagName(<HTML TAG>);
Takes an HTML tag (e.g. 'p' ) and returns a live HTMLCollection of matched elements in
your DOM. Returns an empty HTMLCollection if not matching elements were found.