javascript innerHTML adding instead of replacing

Gmo picture Gmo · Jul 6, 2011 · Viewed 53k times · Source

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)

Answer

jcomeau_ictx picture jcomeau_ictx · Jul 6, 2011
<div id="whatever">hello one</div>
<script>
document.getElementById("whatever").innerHTML += " hello two";
</script>