Javascript DOM HTML Figure Object get

Introduction

The Figure object represents an HTML <figure> element.

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

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

Click the button to get the id of the FIGURE element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>This is a test. This is a test. This is a test. This is a test. This is a test. 
This is a test. This is a test. This is a test. This is a test. This is a test. 
This is a test. This is a test. This is a test. This is a test. This is a test. 
</p>// w ww . j  a  v  a  2s  .  c  o  m

<figure id="myFigure">
  <img src="image1.png" alt="The Circle" width="100" height="100">
</figure>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myFigure").id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related