Description of example:
In the following example code we have created a table which is not having any caption and we will add the caption to this table by using the method createCaption(). We have create a button element in the HTML page which will call the function createCaption() which we have defined in our script tags. To create caption we have used createCaption() method on the table's object and then to add some value to the caption we will use the innerHTML property of the caption object.
Here is the full example code of creating and adding the caption element to the table as described below:
click on the button "Create caption" , it will create and add the table's caption into the table body.