This is an example.
\"; ``` The above code will add a paragraph containing the text \"This is an example.\" to the div element with the ID \"example.\" Similarly, we can use the same property to replace the content of the element with new content. Changing the style of an element is another way of DOM manipulation. We can use the style property to modify the CSS of an element, such as changing its color, font size, or position. For instance, let's say we have an HTML document with a div element as follows: ```htmlHello!
```
We can change the background color of the div element using the following JavaScript code:
```javascript
document.getElementById(\"test\").style.backgroundColor = \"blue\";
```
The above code will change the background color of the div element to blue.
Sub-Properties
Sub-properties are properties of an element that are related to a specific attribute of the element. For instance, the value property of an input element is a sub-property that sets or returns the value attribute of input. Similarly, the id, name, and type properties of an input element are also sub-properties that correspond to their respective attributes.
One use of sub-properties is to manipulate form elements dynamically. For instance, let's say we have the following HTML form:
```html
```
We can use the value property of the input element to change the default value of the input field dynamically. For example, we can use the following code to set the value of the username field to \"John\":
```javascript
document.getElementById(\"username\").value = \"John\";
```
Similarly, we can use the same property to get the current value of the input field, as shown below:
```javascript
var username = document.getElementById(\"username\").value;
```
Conclusion
DOM manipulation and sub-properties are crucial tools for creating interactive and dynamic web applications. With DOM manipulation, developers can change the structure, content, and style of an HTML document dynamically, while sub-properties enable them to manipulate specific attributes of an element, such as its value or type. As such, developers must master DOM manipulation and sub-properties to create engaging and interactive websites that provide a seamless user experience.