PDA

View Full Version : Inner HTML ?


christrinder
05-28-2003, 10:58 AM
Hello,

I think I'm pretty adept when it comes to HTML coding, but there's one element I've never really used before; Inner HTML. To be honest I'm not sure what it is or how to use it. Does anybody know of a good tutorial or care to explain it?

Thanks,
Chris

ronaldb66
05-28-2003, 11:49 AM
InnerHTML is not an element, but an IE proprietary property, available through scripting (like JavaScript). Since it is no part of the W3C DOM I would recommend not using it.
It is said to return, or set if not read-only, the HTML within the referred element.
Do a search on "innerhtml" to get some more info.

brothercake
05-28-2003, 11:59 AM
It is proprietary, but has also been adopted by the major DOM browsers - mozilla, safari/konqueror and Opera 7 all support it, as well as IE5 and IE6. As long as you're working in the HTML DOM (rather than the XML DOM) there are no problems with using innerHTML.

Here's an eg; this HTML:

<p id="container">Here is some <strong>text</strong></p>

you can retrieve the container contents like this:

var cont = document.getElementById('container').innerHTML;

and set it like this

document.getElementById('container').innerHTML = 'Here is some <em>new</em> text';

ronaldb66
05-28-2003, 12:13 PM
Yeah, I found out in the mean time.
Chris, do a search on "innerhtml" in this forum to find more interesting discussion on the topic.