The HTMLTableElement.createCaption()
method returns the caption for the table. If no caption element exists on the table, this method creates it, then returns it.
Syntax
HTMLTableElement = table.createCaption()
Example
mycap = mytable.createCaption();