I have many <section>
in my html <body>
and want to add more through javascript. However, using innerHTML
is just replacing my existing sections with new ones, instead of adding them to the old ones.
What else can I use?
The HTML <body> text Attribute is used to define a color for the text in the Document. Note: The <body> text attribute is not supported by HTML5. Instead of using this attribute, we can use css color property. color_name: It specify the name of the color for the text in the Document.
To append using the innerHTML attribute, first select the element (div) where you want to append the code. Then, add the code enclosed as strings using the += operator on innerHTML.
You can use
document.getElementById("parentID").appendChild(/*..your content created using DOM methods..*/)
or
document.getElementById("parentID").innerHTML+= "new content"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With