<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table id="table-id" style="border:1px solid coral">
<tr><td>abc</td><td>def</td></tr>
<tr><td>ghi</td><td>jkl</td></tr>
</table>
<script>
function createTableCaption(id)
{
document.getElementById(id).createCaption().innerHTML = "Your table caption";
}
/*
run:
On button click table caption will set to: "Your table caption"
*/
</script>
<button onclick="createTableCaption('table-id')">Create Table Caption</button>
</body>
</html>