Javascript Reference - HTML DOM Figure Object








The Figure object represents an HTML <figure> element.

Standard Properties and Events

The Figure object supports the standard properties and events.

Example

We can access a <figure> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<figure id="myFigure">
  <img src="http://java2s.com/style/demo/border.png" alt="test" width="100" height="100">
</figure><!--from  w ww . j ava  2 s.c o m-->
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myFigure").id;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <figure> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button><br><br>
<!--from w w  w. ja  v  a2s  .c  om-->
<script>
function myFunction() {
    var x = document.createElement("FIGURE");
    x.setAttribute("id", "myFigure");
    document.body.appendChild(x);

    var y = document.createElement("IMG");
    y.setAttribute("src", "http://java2s.com/style/demo/border.png");
    y.setAttribute("width", "300");
    y.setAttribute("width", "200");
    y.setAttribute("alt", "an image");

    x.appendChild(y);
}
</script>

</body>
</html>

The code above is rendered as follows: