Javascript DOM HTML Div Object get

Introduction

The Div object represents an HTML <div> element.

We can access a <div> element via document.getElementById():

var x = document.getElementById("myDIV");

Click the button to get the content of the div element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<div id="myDIV">This is a div element.</div>
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related