English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM innerHTML property

HTML DOM Element Object

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.

Syntax:

Return the innerHTML property:

element.innerHTML

Set the innerHTML property:

element.innerHTML = text
document.getElementById("para").innerHTML = "Hello world";
Test and See‹/›

Browser Compatibility

All browsers fully support the innerHTML attribute:

Attribute
innerHTMLYesYesYesYesYes

Attribute Value

ValueDescription
textSpecify the HTML content of the element

Technical Details

Return Value:A string representing the HTML content of the element
DOM Version:DOM Level1

More Examples

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‹/›

Related References

HTML DOM Reference:HTML DOM textContent property

HTML DOM Element Object