Open In App

HTML DOM Style borderCollapse Property

The DOM Style borderCollapse property in HTML is used to set or return whether the border of the table collapsed into a single border or not. 

Syntax:



object.style.borderCollapse 
object.style.borderCollapse = "separate|collapse|initial|inherit" 

Property Values: 

Return Value: It returns a string value that represents a border of the table. 



Example 1: In this example, we will use borderCollapse property.




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style borderCollapse Property
    </title>
</head>
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h2>DOM Style borderCollapse Property</h2>
        <table id="gfg" border="1">
            <tr>
                <th>Student Name</th>
                <th>Age</th>
            </tr>
            <tr>
                <td>Manas Chhabra</td>
                <td>19</td>
            </tr>
            <tr>
                <td>Hritik Bhatnagar</td>
                <td>20</td>
            </tr>
        </table>
        <br>
        <button type="button" onclick="geeks()">
            Submit
        </button>
        <!-- script to collapse border -->
        <script>
            function geeks() {
                document.getElementById("gfg").style.borderCollapse =
                    "collapse";
            }
        </script>
    </center>
</body>
</html>

Output:

 

Example 2: In this example, we will collapse the border by using the property. 




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Style borderCollapse Property
    </title>
</head>
<body>
    <center>
        <h1>GeeksforGeeks</h1>
        <h2>DOM Style borderCollapse Property</h2>
        <table id="gfg" border="1"
               style="border-collapse:collapse;">
            <tr>
                <th>Student Name </th>
                <th>Age</th>
            </tr>
            <tr>
                <td>Manas Chhabra</td>
                <td>19</td>
            </tr>
            <tr>
                <td>Hritik Bhatnagar</td>
                <td>20</td>
            </tr>
        </table>
        <br>
        <button type="button" onclick="geeks()">
            Submit
        </button>
        <!-- script to return borderCollapse value -->
        <script>
            function geeks() {
                alert(
                document.getElementById("gfg").style.borderCollapse);
            }
        </script>
    </center>
</body>
</html>

Output:

 

Supported Browsers: The browser supported by DOM Style borderCollapse property are listed below:


Article Tags :