Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

innerHTML

The innerHTML property of the Element object is used to return or change everything in between the opening and closing tags of an element. In order to return plain text only ignoring the HTML markup, use the textContent property instead.

Syntaxelement.innerHTML
<div id="div1">This is my <b>DIV</b> content.</div> <script> alert( document.getElementById("div1").innerHTML ); </script>

Change the innerHTML

document.getElementById("div1").innerHTML = "New <b>HTML</b> content";

Append (add to the end)

document.getElementById("div1").innerHTML += " More <b>HTML</b> content.";

Prepend (add to the beginning)

var existing = document.getElementById("div1").innerHTML; document.getElementById("div1").innerHTML = "Prepended <b>HTML</b> content. " + existing;

JavaScript

Properties

bodycalleeclosedcookiedocumentdropEffecteffectAllowedfilesframeElementframeshistoryInfinityinnerHeightinnerHTMLinnerWidthlengthlocationlocationbarnameNaNnavigatornullopenerouterHeightparentprototypescreenstatetextContentundefined