Tips Trick innerHTML

Be careful when using innerHTML in Javascript! If you seem can not add some html tags into it, do not be confused. You should evaluate whole tags ( opening and closing tags ) as single statement.

This code should explain better:

obyek.innerHTML += "<a href='somewhere'>"
obyek.innerHTML += "Click here"
obyek.innerHTML += "</a>"

code above will not work ("click here" is not a link) , but this will:

s = "<a href='somewhere'>"
s += "Click here"
s += "</a>
obyek.innerHTML += s

The latter code will work because we have joined whole string into s, then append it to innerHTML. "Click here" become a link now.


Popular posts from this blog

Ports to allow for whatsapp call

Setting open office u label tom & jerry

Tips Jika Mobil Anda Habis Bensin LOL!