quick question, i know we can change the content of a
<div id="whatEverId">hello one<div>
by using:
document.getElementById("whatEverId").innerHTML="hello two";
now, is there a way I can ADD stuff to the div instead of replacing it??? so i can get
<div id="whatEverId">hello one hello two<div>
(using something similar of course)
Appending to innerHTML is not supported: Usually, += is used for appending in JavaScript. But on appending to an Html tag using innerHTML, the whole tag is re-parsed.
Yes, setting the . innerHTML properties overwrites any previous value for that property.
The use of innerHTML creates a potential security risk for your website. Malicious users can use cross-site scripting (XSS) to add malicious client-side scripts that steal private user information stored in session cookies.
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.
<div id="whatever">hello one</div> <script> document.getElementById("whatever").innerHTML += " hello two"; </script>
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