Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h3>A demonstration of how to access a FIGURE element</h3>
<p>The Pulpit Rock is a massive cliff 604 metres (1982 feet) above Lysefjorden, in Forsand, Ryfylke, Norway.</p>
<figure id="myFigure">
  <img src="/tags/img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">
</figure>
<p>Click the button to get the id of the FIGURE element.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("myFigure").id;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>