Javascript DOM TableData Get And Set Column Span Property
Có thể bạn quan tâm
Example
Change the number of columns a table cell should span:
Copy document.getElementById("myTd").colSpan = "1"; Open in separate windowView full source codeCopy<!DOCTYPEhtml> <html> <head> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <p>Click the button to change the value of the colspan attribute, from 2 to 1, of td with id "myTd".</p> <table> <tr> <th>Month</th> <th>Usage</th> </tr> <tr> <td id="myTd" colspan="2">January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$100</td> </tr> </table> <br> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myTd").colSpan = "1"; } </script> </body> </html>Description
The colSpan property gets and sets the value of the colspan attribute.
The colspan attribute specifies the number of columns a table cell should span.
We can use the rowSpan property to set or return the value of the rowspan attribute.
Browser Compatibility
colSpan | Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the colSpan property:
Copy let a = tabledataObject.colSpan;Set the colSpan property:
Copy tabledataObject.colSpan = number;Property Values
Parameter | Description |
---|---|
number | the number of columns a cell should span |
Return Value
A Number, representing the number of columns a table cell should span
More Examples
Return the number of columns a specific table cell should span:
Copy let x = document.getElementById("myTd").colSpan; Open in separate windowView full source codeCopy<!DOCTYPEhtml> <html> <head> <style> table, th, td { border: 1px solid black; } </style> </head> <body> <p>Click the button to return the value of the colspan attribute of td with id "myTd".</p> <table> <tr> <th>Month</th> <th>Usage</th> </tr> <tr> <td id="myTd" colspan="2">January</td> <td>$100</td> </tr> <tr> <td>February</td> <td>$100</td> </tr> </table> <br> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction(x) { let x = document.getElementById("myTd").colSpan; document.getElementById("demo").innerHTML = "The value of colspan is: " + x; } </script> </body> </html> PreviousNextRelated
- Javascript DOM TBody Object
- Javascript DOM TableData Object
- Javascript DOM TableData Get and Set cell Index Property
- Javascript DOM TableData Get and Set column Span Property
- Javascript DOM TableData Get and Set headers collection Property
- Javascript DOM TableData Get and Set row Span Property
- Javascript DOM Textarea Object
Từ khóa » Html Colspan Javascript
-
HTML DOM TableData ColSpan Property - W3Schools
-
HTML Td Colspan Attribute - W3Schools
-
ColSpan Property (td, Th) JavaScript - Dottoro Web Reference
-
Set Colspan/rowspan For A Cell - Javascript - Stack Overflow
-
Javascript Reference - HTML DOM TableData ColSpan Property
-
Table Rowspan And Colspan In HTML Explained (With Examples) »
-
HTML Colspan Attribute - HTML Tutorials - W3resource
-
iaColSpan - Web APIs | MDN
-
HTML Colspan Attribute
-
The Table Element - HTML: HyperText Markup Language | MDN
-
HTML | DOM TableData ColSpan Property - GeeksforGeeks
-
HTML DOM TableHeader ColSpan Property - GeeksforGeeks
-
HTML Th Colspan Attribute - W3Schools
-
How To Change Colspan=“6” To Colspan =“4” In TD Using JQuery ...