JavaScript HTML DOM - Changing CSS
JavaScript can modify the appearance of HTML elements using the HTML DOM.
Changing HTML Style
To modify how an HTML element looks, follow this syntax:
document.getElementById(id).style.property = new style
In this example, the style of a
element is modified.
Using Events
The HTML DOM lets you run code when something happens on a webpage.
The browser creates events when "things happen" to HTML elements.
- A click occurs on an element.
- The webpage is ready.
- Input fields have been modified.
In the upcoming chapter of this tutorial, you'll gain additional insights into events.
This example modifies the appearance of the HTML element identified as id="id1"
when the user clicks a button.