HTML/Javascript change div content

Rob picture Rob · Mar 31, 2010 · Viewed 598.1k times · Source

I have simple HTML code with some javascript, it looks like:

I just wanted to be able to change the div's content (it's inner html) with selecting one of "A" or "B" radio buttons, but div#content does not have javascript attribute "value", so I am asking how it can be done.

Answer

Syntactic picture Syntactic · Mar 31, 2010

Assuming you're not using jQuery or some other library that makes this sort of thing easier for you, you can just use the element's innerHTML property.

document.getElementById("content").innerHTML = "whatever";