querySelectorAll
will select
all the HTML elements which match the
provided query. This is a versatile
selector
and
can match elements using any of the
CSS selectors, including class names, tag names,
id names or any complex selectors too.
The method returns an array-like
list of all the matched DOM elements. You
can iterate over it using loops, or
you can convert it to an array using
Array.from()
.
The selectors that we pass in this
method are simply the selectors
that we have used in CSS. This means you
can use #
to select using the id, .
to
select the elements using their class.
You can go as detailed as possible
with your selectors.
For example, the inspirationConfirmation
variable gets its value through a complex
CSS selector in document.querySelector('#brutal-paragraph>span')
.