Locked lesson.
About this lesson
How to change your CSS with JavaScript.
Exercise files
Download this lesson’s related exercise files.
Changing CSS.docx59 KB Changing CSS - Solution.docx
59.1 KB
Quick reference
Changing CSS
JavaScript makes changing CSS very easy.
When to use
Do this any time you want to change CSS style on a web page.
Instructions
Given this p tag:
<p id="first">Hello World!</p>
To change the CSS style to make the text blue, we would do this:
document.getElementById("first").style.color = "blue";
.style.property can change any CSS!
Hints & tips
- .style.property can change any CSS
- Remember to use lowercase Camel Case when renaming CSS properties that normally have dashes
Lesson notes are only available for subscribers.