Accessing elements in the DOM
There are multiple methods to select elements from the DOM. After getting the elements, we are able to modify them. In the following sections, we will discuss how to get elements by their ID, tag name, and class name, and by CSS selector.
Instead of traversing it step by step as we just did, we are going to use built-in methods that can go through the DOM and return the elements that match the specifications.
We are going to use the following HTML snippet as an example:
<!DOCTYPE html>
<html>
<body>
<h1>Just an example</h1>
<div id="one" class="example">Hi!</div>
<div id="two" class="example">Hi!</div>
<div id="three" class="something">Hi!</div>
</body>
</html>
Let's start by accessing elements by ID.
Accessing elements by ID
We can grab elements by ID with the getElementById...