Create a Caption Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Caption


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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
table, th, td {
    border: 1px solid black;
    margin-top: 20px;
</style>/*  ww  w.  j  ava2 s .  c o m*/

<button onclick="myFunction()">Test</button>

<table id="myTable">

function myFunction() {
    var x = document.createElement("CAPTION");
    var t = document.createTextNode("this is the caption");

    var table = document.getElementById("myTable")
    table.insertBefore(x, table.childNodes[0]);


Related Tutorials