Get Figcaption Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Figcaption

Introduction

The Figcaption object represents an HTML <figcaption> element.

You can access a <figcaption> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<figure>
  <img src="http://java2s.com/resources/a.png" alt="alt message" width="300" height="200">
  <figcaption id="myFigCap">Fig.1 - an image.</figcaption>
</figure>/*w ww .j  a  v a2  s .  c om*/

<button onclick="myFunction()">set the color of the caption to red</button>

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

</body>
</html>

Related Tutorials