Locked lesson.
About this lesson
Finding elements by ID, by tag name, by class name, by CSS selectors, and by collections.
Exercise files
Download this lesson’s related exercise files.
Finding Dom Elements.docx59 KB Finding Dom Elements - Solution.docx
59.1 KB
Quick reference
Finding Dom Elements
We've looked at several DOM methods. In this video we'll learn how to use them.
When to use
This is another method for manipulating DOM elements.
Instructions
To use getElementsByTagName():
myVar = document.getElementsByTagName("h1");
document.write(myVar[0].innerHTML);
To use document.getElementsByClassName():
myVar = document.getElementsByClassName("name");
document.write(myVar[0].innerHTML);
The list of HTML Object Collections:
document.title
document.anchors
document.body
document.forms
document.head
document.images
document.links
document.scripts
Hints & tips
- Remember, to access items in getElementsByTagName() and getElementsByClassName() you have to reference index numbers
Lesson notes are only available for subscribers.