- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Table Object
The HTML DOM table Object represent the <table> element of an HTML document.
Let us see how to create table object
Syntax
Following is the syntax −
document.createElement(“TABLE”);
Properties
Following are the properties of table object −
Property | Explanation |
---|---|
caption | It returns <caption> element of a table in an HTML document. |
tFoot | It returns <tfoot> element of a table in an HTML document. |
tHead | It returns <thead> element of a table in an HTML document. |
Methods
Following are the methods of table object −
Method | Explanation |
---|---|
createCaption() | It generates an empty <caption> element and adds it to the table. |
createTFoot() | It generates an empty <tfoot> element and adds it to the table. |
createTHead() | It generates an empty <thead> element and adds it to the table. |
deleteCaption() | It delete the first <caption> element from the table. |
deleteRow() | It deletes a <tr> element from the table. |
deleteThead() | It delete the <thead> element from the table. |
deleteTFoot() | It delete the <tfoot> element from the table. |
insertRow() | It generates an empty <tr> element and adds it to the table. |
Example
Let us see an example of table object −
<!DOCTYPE html> <html> <head> <style> body { text-align: center; background-color: #fff; color: #0197F6; } h1 { color: #23CE6B; } .btn { background-color: #fff; border: 1.5px dashed #0197F6; height: 2rem; border-radius: 2px; width: 60%; margin: 2rem auto; display: block; color: #0197F6; outline: none; cursor: pointer; } </style> </head> <body> <h1>DOM table Object Demo</h1> <button onclick="createTable()" class="btn">Create a table object</button> <script> function createTable() { var table = document.createElement("TABLE"); table.innerHTML = `<tr> <td>Data 1</td> <td>Data 2</td> </tr> <tr> <td>Data 3</td> <td>Data 4</td> </tr>`; table.setAttribute('border', "2"); table.style.margin = "2rem auto"; document.body.appendChild(table); } </script> </body> </html>
Output
This will produce the following output −
Click on “Create a table object” button to create a table object.
Advertisements