Using the getElementById method

In HTML, you can assign an element an ID and then retrieve it back in JavaScript for manipulation. Here's how:

<div id="myID">My Content Here</div><script>const myID = document.getElementById('myID'); // myID now contains reference to the div above</script>

Once you have that, you can access the properties of this object, which in turn actually modifies the element on the screen accordingly.

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.