Table object method createCaption() in Javascript
The table object method createCaption() used to an empty caption element and adds it to the table. If table caption already exist for the table, the createCaption() method returns an existing one and does not create new caption. It returns a newly created or an existing caption element.
Syntax
 1 <table>.createCaption()
table : A table element object to create or retrieve caption by using createCaption() method
Table method createCaption()
 1 <!DOCTYPE html>
 2 <html>
 3 <style>
 4   .container {
 5     margin: 10px 0;
 6   }
 7   table, tr, td {
 8   	width: 450px;
 9     height: 50px;
 10   }
 11 </style>
 12 <body>
 13 	<h1>The Table Object</h1>
 14 	<h2>Example</h2>
 15 	
 16 	<div class="container">
 17 	 <table id="table" border="1" cellspacing="0">
 18 	  <tr>
 19 	    <td>cell 1</td>
 20 	    <td>cell 2</td>
 21 	  </tr>
 22 	  <tr>
 23 	    <td>cell 3</td>
 24 	    <td>cell 4</td>
 25 	  </tr>
 26 	</table>
 27 	</div>
 28 	<button onclick="access()">Create caption</button>
 29 	
 30 	<p id="result"></p>
 31 	<script>
 32 	function access() {
 33 	  const element = document.getElementById("table");
 34 	  const caption = element.createCaption();
 35 	  caption.innerHTML = `Dynamica table caption`;
 36 	  const str = `Table caption created !`;
 37 	  document.getElementById("result").innerHTML = str;
 38 	}
 39 	</script>
 40 </body>
 41 </html>
 42 
Table method createCaption()
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us