Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Select an Element by ID 6:21
- Select by ID 2 objectives
- Select Elements by Tag Name 7:40
- Select by Tag Name 1 objective
- Select Elements by Class Name 3:48
- Selection Review 5 questions
- Use CSS Queries to Select Page Elements 6:10
- Getting a Handle on the DOM Review 5 questions
- Return Elements Using CSS Selectors 3 objectives

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
There is a two-step sequence when controlling an element in the DOM with JavaScript. First, you access the element, and then you can either read its contents or manipulate it somehow. There are several ways to access specific elements in the DOM. In this video, you'll select an element by its ID, with the getElementById()
method.
Further Reading
Using const
for assigning elements in the DOM to variables
The keyword const
prevents re-assignment to a variable. So using const
prevents you from changing what element (or node) the variable points to, which could create errors in your program or affect its behavior.
Common Errors
- Spelling - If you get an undefined error when trying to access an element, you may have incorrectly spelled the argument passed to the method
- Case Sensitivity - Make sure your capitalizations are proper camelCase, and the correct letters are capitalized
Experiment with the app
- Set a different
style
property of the headline, such as the font-size, font-family or color - Add a button that resets the heading styles when clicked
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Jason Beton
Full Stack JavaScript Techdegree Student 463 Points1 Answer
-
Turandeep Munday
6,047 Points1 Answer
-
Peter Huang
5,427 Points1 Answer
-
Alex Hort-Francis
17,074 Points1 Answer
-
JASON LEE
17,352 Points1 Answer
-
Javier Perez Narvaez
15,007 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up