Javascript DOM HTML Element innerHTML Property get

Introduction

Get the HTML content of a <p> element with id="myP":

var x = document.getElementById("myP").innerHTML;

Click the button get the HTML content of the p element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP">I am a paragraph.</p>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  w w w.j a  v a  2 s  . c o m*/
  var x = document.getElementById("myP").innerHTML;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related