Element Selection
Old School
Selecting an element by id
This code will return the first element having the given id.
Select using CSS class
This code will return the first element having the blog-post-content
CSS class.
Select by HTML tag
This code will return the first element having the header
HTML tag.
Modern Way
Select using query selector
The first call will return the first element with the header HTML tag.
The second call will return an iterable object with all the items with a div
HTML tag and the blog-post-content
CSS class.
This is the easier and most modern way of selecting elements.
querySelector
and querySelectorAll
methods are also available on every element in order to search for child elements.
Last updated