X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM innerHTML Property

HTMLElement Object Reference Element Object

Example

Change the text of a <p> element with id="demo":

document.getElementById("demo").innerHTML = "Paragraph changed!";

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The innerHTML property sets or returns the HTML content (inner HTML) of an element.


Browser Support

Property
innerHTML Yes Yes Yes Yes Yes


Syntax

Return the innerHTML property:

HTMLElementObject.innerHTML

Set the innerHTML property:

HTMLElementObject.innerHTML=text

Property Values

Value Description
text Specifies the HTML content of an element

Technical Details

Return Value: A String, representing the HTML content of an element


Examples

More Examples


Example

Change the text of two elements:

document.getElementById("myP").innerHTML = "Hello Dolly.";
document.getElementById("myDIV").innerHTML = "How are you?";

Try it yourself »

Example

Alert the text of a <p> element with id="demo":

alert(document.getElementById("demo").innerHTML);

Try it yourself »

Example

Delete the text of a <p> element with id="demo":

document.getElementById("demo").innerHTML = "";  // Replaces the content of <p> with an empty string

Try it yourself »

Example

Change the text, URL, and target of a link:

document.getElementById("myAnchor").innerHTML = "W3Schools";
document.getElementById("myAnchor").href = "http://www.w3schools.com";
document.getElementById("myAnchor").target = "_blank";

Try it yourself »


HTMLElement Object Reference Element Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook