Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; margin-top: 20px; } </style> </head> <body> <p>Click the button to create a CAPTION element.</p> <button onclick="myFunction()">Try it</button> <table id="myTable"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$50</td> </tr> </table> <script> function myFunction() { var x = document.createElement("CAPTION"); var t = document.createTextNode("Monthly savings"); x.appendChild(t); var table = document.getElementById("myTable") table.insertBefore(x, table.childNodes[0]); } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_caption_create by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:01:04 GMT --> </html>
Result:
Try it Yourself - © w3schools.com