HTML elements can be changed using JavaScript, the HTML DOM and events.
HTML DOM and JavaScript can change the inner content and attributes of HTML elements.
The following example changes the background color of the <body> element:
The easiest way to get or modify the content of an element is by using the innerHTML property.
The following example changes the text of a <p> element:
An event handler allows you to execute code when an event occurs.
Events are generated by the browser when the user clicks an element, when the page loads, when a form is submitted, etc.
You can read more about events in the next chapter.
The following example changes the background color of the <body> element when a button is clicked:
The following example uses a function to change the text of the <p> element when a button is clicked:
The Style object of each HTML element represents its individual style.
The following example uses a function to change the style of the <body> element when a button is clicked:
The following example uses a function to change the style of the <p> element when a button is clicked:
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|