Hi,
Using javascript, I would like to replace the contents of a DIV with
new, arbitrary HTML markup. I want to write a W3C-compliant function
for doing so; it would look something like this:
function changeContents(divElement, htmlMarkup)
{
// divElement: an existing DIV object reference
// htmlMarkup: new HTML markup to replace whatever is there
}
Consider the following code:
<div id='Div1'><p>some <strong>important</strong> stuff</p></div>
If I called my function like so:
changeContents(document.getElementById('Div1'),'<h 1>Yay!</h1>');
the expect rendering would be:
<div id='Div1'><h1>Yay!</h1></div>
I've read many suggestions using nodes manipulation, but all of them
seemed to work only if you're just adding plain text -- not HTML tags.
In the latter case, I've seen suggestions to use createElement() which
is fine when you *know* exactly what you're adding... but what about a
function?
I hope I'm making sense here... Any ideas will be greatly appreciated,
Thanks!