English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
innerHTML ofThe property sets or returns the HTML content of the element.
Note:If the child text node of the <div>, <span>, or <noembed> element contains characters (&), (<), or (>), innerHTML will treat these characters as HTML entities “&amp;”, “&lt;”, and “&gt;” respectively. UsetextContentThe property retrieves the original copy of the text node content.
Return the innerHTML property:
element.innerHTML
Set the innerHTML property:
element.innerHTML = text
document.getElementById("para").innerHTML = "Hello world";Test and See‹/›
All browsers fully support the innerHTML attribute:
Attribute | |||||
innerHTML | Yes | Yes | Yes | Yes | Yes |
Value | Description |
---|---|
text | Specify the HTML content of the element |
Return Value: | A string representing the HTML content of the element |
---|---|
DOM Version: | DOM Level1 |
Use id="para" to get the HTML content of the <p> element:
var x = document.getElementById("para").innerHTML;Test and See‹/›
You can clear the entire content of the document by clearing the content of the body attribute:
document.body.innerHTML = "";Test and See‹/›
HTML DOM Reference:HTML DOM textContent property