May 09, 2021 HTML DOM
By the end of this section, you'll learn how to modify HTML to change elements, properties, styles, and events.
Modifying HTML DOM means many different things:
In the next section, we'll dive into the common ways to modify HTML DOM.
The easiest way to change the content of an element is to use the innerHTML property.
The following example changes the HTML content of an element:
We'll explain the details of the examples to you in the following sections, and I hope you'll have a better understanding of the above examples. |
HTML DOM allows you to access style objects for HTML elements.
Here's an example of changing the HTML style of a paragraph that you can try to modify:
<p id="p2">Hello world!</p>
<script>
document.getElementById("p2").style.color="blue";
</script>
</body>
</html>
If you need to add a new element to the HTML DOM, you must first create the element (element node) and then append it to the existing element.
Learn HTML DOM modifications and recommend that you do more hands-on exercises, preferably by doing several instances of this section.