Now we will learn how to get the page DOM elements in order to perform some manipulations with them in the future.
Let's have some button:
<input id="button" type="submit">
Let's get a reference to this button into
a variable. To do this, use the
method of the special object
This method takes a CSS selector as a parameter
and returns a reference to the element found
with this selector.
Our button has an attribute
button. So we can find
this button by the selector
So, let's find our button and write a
reference to it into a variable:
let button = document.querySelector('#button'); console.log(button);
<p id="elem1">1</p> <p id="elem2">2</p> <p id="elem3">3</p>
Put the reference to each of the paragraphs in a separate variable and print the contents of each of these variables to the console.