Create a Figcaption Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Figcaption

Introduction

You can create a <figcaption> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">create a FIGCAPTION element with some text</button><br><br>

<figure id="myFigure">
  <img src="http://java2s.com/resources/a.png" alt="alt message" width="300" height="200">
</figure>/*from w  w  w.j  a v  a  2 s .co  m*/

<script>
function myFunction() {
    var x = document.createElement("FIGCAPTION");
    var t = document.createTextNode("Fig.1 - an image.");
    x.appendChild(t);
 
    var y = document.getElementById("myFigure");
    y.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials