[Javascript] innerHTML

Peter-Paul Koch gassinaumasis at hotmail.com
Thu Aug 23 09:21:58 CDT 2001


>Can somebody please elaborate a little on "innerHTML". I have heard it
>mentioned at various places. What does it do exactly? Is it part of
>JavaScript, CSS, or what? Will appreciate a short summary or some good 
>links on the topic.

innerHTML is JavaScript, originally a Microsoft invention, first implemented 
in IE4. It gives access to the HTML + text that is inside a certain HTML 
element (a DIV), for instance. It is very powerful because you can change 
the HTML.

Suppose you have this DIV:

<DIV ID="test">This is some <b>really cool</b> text.</DIV>

If you say

document.getElementById('test').innerHTML = 'But this is <em>boring</em> 
text';

the content of the DIV changes immediately.

Not supported in NN4, but it is in Netscape 6 and all modern browsers 
supporting the W3C DOM. Although it is not part of the W3C specification it 
is so useful that it should.

There also exists innerText, which is the same execpt that it doesn't take 
notice of any HTML tags. Finally you have outerHTML and outerText, these are 
almost the same except that they also contain the HTML tag itself (in my 
example it contains the DIV ID="test").

ppk

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list