Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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