Bootcamp
Search…
1.2.3: Grab an Element

Introduction

Using the DOM we can create a JS representation of an element that's on the screen.
For example, if the following element existed in our HTML...
1
<p id="wow">cool :)</p>
Copied!
... we could use DOM code to "grab" the element and obtain a JS representation it. We can then perform DOM manipulation on this JS representation.
1
const wowParagraph = document.querySelector('#wow');
Copied!

Grab Any Element

To review how element selection works, see the examples on the following page. We can get references to any element in the DOM. https://www.w3schools.com/jsref/met_document_queryselector.asp​