Finding HTML Elements in JavaScript

There are three ways to find HTML elements using JavaScript. You can search for them by the ID attribute name, by the class name, or by the tag type. The following code shows an example of defining an HTML <div> element so that each of these methods can use it:

<div id="myDiv" class="myClass">Content</div>

By adding the ID and class attributes, you can use those values of "myDiv" and "myClass" to search for the <div> element.

Get jQuery and JavaScript Phrasebook 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.