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 Below 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 Below 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 Below example changes the background color of the <body> element when a button is clicked:
The Below 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 Below example uses a function to change the style of the <body> element when a button is clicked:
The Below example uses a function to change the style of the <p> element when a button is clicked:
Your Query was successfully sent!