+ 2

Why the output is coder?

<div id ="test"></div> <script> var a =document.getElementById("test"); a.innerHTML="hello"; a.innerHTML="CODER!"; </script>

17th Oct 2017, 4:04 AM
Saurabh Rauthan
Saurabh Rauthan - avatar
7 Answers
+ 4
if you want the output is helloCODER!, concat the both a variable <div id ="test"></div> <script> var a =document.getElementById("test"); a.innerHTML="hello"; a.innerHTML+="CODER!"; </script>
17th Oct 2017, 5:56 AM
MBZH31
MBZH31 - avatar
+ 3
CODER was overwrite hello
17th Oct 2017, 4:29 AM
æž—ć‰é›„
æž—ć‰é›„ - avatar
+ 3
a.innerHTML = "CODER!" is overwriting previous value of a.innerHTML
17th Oct 2017, 9:58 AM
stn
stn - avatar
+ 2
u want output hello CODER u need use "+="
17th Oct 2017, 4:30 AM
æž—ć‰é›„
æž—ć‰é›„ - avatar
+ 2
thanx all ...what sololearn is today is all about you !!
17th Oct 2017, 11:09 AM
Saurabh Rauthan
Saurabh Rauthan - avatar