Javascript DOM HTML Element innerHTML Property set

Introduction

The innerHTML property sets or gets the HTML content, inner HTML, of an element.

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo" onclick="myFunction()">Click me to change my HTML content (innerHTML).</p>

<script>
function myFunction() {/*from w  ww .j a va2s .  c  o m*/
  document.getElementById("demo").innerHTML = "Paragraph changed!";
}
</script>

</body>
</html>

The innerHTML property returns a String, representing the HTML content of an element.




PreviousNext

Related