Get Caption Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Caption

Introduction

The Caption object represents an HTML <caption> element.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}
</style>//from   ww  w.  ja  va  2s .  c om
</head>
<body>

<table>
  <caption id="myCaption">this is the caption</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>

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

<script>
function myFunction() {
    var x = document.getElementById("myCaption");
    x.style.color = "red";
    x.style.border = "1px blue solid";
}
</script>

</body>
</html>

Related Tutorials