Javascript DOM HTML Figcaption Object get

Introduction

The Figcaption object represents an HTML <figcaption> element.

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

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

Click the button to set the color of the caption to red.

View in separate window

<!DOCTYPE html>
<html>
<body>
<figure>
  <img src="image1.png" alt="The Circle" width="100" height="100">
  <figcaption id="myFigCap">Fig.1 - A picture of a circle.</figcaption>
</figure>/*from   ww  w .ja  v  a2 s. c om*/
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  var x = document.getElementById("myFigCap");
  x.style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related