XML DOMLesson 33Free preview
DOM Accessing
This lesson is part of XML · All levels
Summary
DOM provides many ways to access nodes: getElementById for a specific id, getElementsByTagName and getElementsByClassName for a set of elements, as well as querySelector for CSS selection. Attributes are read with getAttribute and written with setAttribute. Choosing the right method makes the code more concise and efficient.
Key points
- GetElementById takes one element based on the id attribute
- GetElementsByTagName returns a set of named elements
- QuerySelector accepts CSS selections such as 'product > price'
- GetAttribute reads the attribute value of an element
- CSS selection is more flexible than manual search
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.