TOC PREV NEXT INDEX

domref



innerHTML


innerHTML returns all of the markup and content within a given element.

Syntax

HTML = element.innerHTML
 

Parameters

HTML is a string that contains the current element and its content (including child elements) as raw HTML

Example

// HTML:
 
// <div id="d"><p>Content</p>
 
// <p>Further Elaborated</p>
 
// </div>
 
d = document.getElementById("d");
 
dump(d.innerHTML);
 

 
// the string "<p>Content</p><p>Further Elaborated</p>"
 
// is dumped to the console window
 

Notes

Though not actually a part of the DOM spec, this property gives the web developer enormous flexibility over the contents of a web page. Consider the following example, where a script sets the blah blah..

// nuther example

You can get the HTML and text contained within any element-including BODY or HTML-and parse it yourself or blah blah. You can also set this property, which means that you can control the contents of the document by adding to or subtracting from the innerHTML. This third example gives you an idea about how evil this can be when it falls into the wrong hands.

// third example

Note that when you append to the innerHTML of a document, you have essentially created a new document. The session history for the browser is incremented, and when you go Back, the document is there in its original, unappended state.

Specification

DOM Level 0. Not part of specification.


Netscape Communications
http://developer.netscape.com
TOC PREV NEXT INDEX