Locked lesson.
About this lesson
How to change HTML output, content, and attributes with JavaScript.
Exercise files
Download this lesson’s related exercise files.
Changing HTML Output, Content, and Attributes.docx59.1 KB Changing HTML Output, Content, and Attributes - Solution.docx
59.1 KB
Quick reference
Changing HTML Output, Content, and Attributes
We can manipulate HTML attributes with JavaScript.
When to use
Anytime you want to change the content of an HTML attribute, you'll use this.
Instructions
HTML attributes add a little extra information to an HTML tag.
We can easily manipulate attributes with JavaScript.
Use these just like you use .innerHTML
Example: An image with the id of hiking and a height attribute of 200. To change the height to 400, write:
document.getElementById("hiking").height = 400;
Hints & tips
- HTML attributes add a little extra info to an HTML tag
- We can change them by calling .theirName just like we call .innerHTML
- To change a title, call .title
- To change the href, call .href
Lesson notes are only available for subscribers.