innerHTML sets or gets all of the markup and content within a given element.
var markup = element.innerHTML; element.innerHTML = markup;
// 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
Though not actually a part of the W3C DOM specification, this property provides a simple way to completely replace the contents of an element. For example, the entire contents of the document body can be deleted by:
document.body.innerHTML = ""; // Replaces body content with an empty string.
The innerHTML property of many types of elements—including BODY or HTML—can be returned or replaced. It can be used to view the source of a page that has been modified dynamically:
As there is no public specification for this property, implementations differ widely. For example, when text is entered into a text input, IE will change the value attribute of the input's innerHTML property but Gecko browsers do not.
It should never be used to write parts of a table—W3C DOM methods should be used for that—though it can be used to write an entire table or the contents of a cell.
DOM Level 0 不属于任何标准.