Selecting Elements in the DOM
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
Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.
✨ Frag Lara — deine KI-Lernpartnerin
Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.
Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.


