HTML | DOM TableData ColSpan Property - GeeksforGeeks
Có thể bạn quan tâm
The Dom TableData colSpan Property in HTML DOM is used to set or return the value of a colspan attribute. The colspan attribute is used to specify the number of columns a table should span.
Syntax:
- It returns the colSpan property.
- It is used to set the colSpan property.
Property Values: It contains the numeric value which specifies the number of columns a cell should span.
Return Value: It returns a numeric value that represents the number of columns that a cell should span.
Example-1: This Example returns a colspan Property.
HTML
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid green; } </style> </head> <body> <h1 style="color:green;"> GeeksForGeeks </h1> <h2> DOM TableData Colspan Property </h2> <table> <tr> <td id="myTd" colspan="3"> Geeks </td> <td>For</td> <td>Geeks</td> </tr> </table> <br> <button onclick="myFunction()"> Click Here! </button> <p id="demo" style="font-size:24px; colorgreen;"> </p> <script> function myFunction() { // return Table data colSpan Property var x = document.getElementById( "myTd").colSpan; document.getElementById("demo").innerHTML = x; } </script> </body> </html> |
Output: Before Clicking On Button:
After Clicking On Button:
Example-2: This Example sets the colspan Property.
HTML
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid green; } </style> </head> <body> <h1 style="color:green;"> GeeksForGeeks </h1> <h2> DOM TableData Colspan Property </h2> <table> <tr> <td id="myTd" colSpan="3"> Geeks </td> <td>For</td> <td>Geeks</td> </tr> </table> <br> <button onclick="myFunction()"> Click Here! </button> <p id="demo" style="font-size:24px; colorgreen;"> </p> <script> function myFunction() { // set Table data colSpan Property var x = document.getElementById("myTd").colSpan = "5"; document.getElementById("demo").innerHTML = "The value of the Colspan " + "attribute was changed to " + x; } </script> </body> </html> |
Output: Before Clicking On Button:
After Clicking On Button:
Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge
- Opera
- Safari
M
ManasChhabra2 Follow Improve Article Tags :- HTML
- Web Technologies
- HTML-DOM
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
-
Javascript DOM TableData Get And Set Column Span 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 TableHeader ColSpan Property - GeeksforGeeks
-
HTML Th Colspan Attribute - W3Schools
-
How To Change Colspan=“6” To Colspan =“4” In TD Using JQuery ...