Selecting Elements in the DOM

DOM IntroductionManipulating Elements

To change or read parts of a web page, you first need to select the elements you want to work with. JavaScript provides several methods for finding elements by ID, class, tag name, or CSS selectors.

Selected elements return Element objects (or collections) that you can then manipulate.

getElementById – Select by Unique ID

Fastest way to select a single element with an id attribute.

querySelector – Most Flexible (CSS Selector)

Returns the first element matching a CSS selector.

querySelectorAll – Get All Matches

Returns a NodeList (array-like) of all matching elements.

getElementsByClassName and getElementsByTagName

Return live HTMLCollections.

Choosing the Right Selector

  • getElementById – fastest for single unique element.
  • querySelector – most flexible (any CSS selector).
  • querySelectorAll – when you need multiple elements.
  • getElementsBy* – older methods, live collections.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.