Skip to content
Related Articles

Related Articles

HTML | DOM TableData headers Property
  • Difficulty Level : Basic
  • Last Updated : 14 Jun, 2019

The HTML | DOM TableData headers Property is used to set or return the value of a header’s attribute. The header’s attribute is used to specify the a table cell containing Header information for the current data cell.

Syntax:

  • It returns the headers property.
    tabledataObject.headers
  • It is used to set the headers property.
    tabledataObject.headers = header_ids

Property Values: It contains the value i.e header_ids which specify the separated list of id’s to one or mpre header cell .

Return Value: It returns a string value which represents the separated list of header-list Id’s.

Example-1: This Example returns a headers Property.






<!DOCTYPE html>
<html>
  
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid green;
        }
    </style>
</head>
  
<body>
  
    <h1 style="color:green;"
            GeeksForGeeks 
        </h1>
  
    <h2>
          DOM TableData Headers Property
      </h2>
  
    <table>
        <tr>
            <td id="myTd"
                headers="Geeks" 
                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() {
            // Accessing Table data 
            var x =
                document.getElementById(
                    "myTd").headers;
  
            document.getElementById("demo").innerHTML =
                x;
        }
    </script>
</body>
  
</html>

Output:
Before Clicking On Button:

After Clicking On Button:

Example-2: This Example sets a header’s Property.




<!DOCTYPE html>
<html>
  
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid green;
        }
    </style>
</head>
  
<body>
  
    <h1 style="color:green;"
            GeeksForGeeks 
        </h1>
  
    <h2>
          DOM TableData Headers Property
      </h2>
  
    <table>
        <tr>
            <td id="myTd"
                headers="Geeks" 
                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() {
            // Accessing Table data 
            var x =
                document.getElementById(
                    "myTd").headers = "GFG";
  
            document.getElementById("demo").innerHTML =
                "The value od the headers attribute was changed to "
            + x;
        }
    </script>
</body>
  
</html>

Output:
Before Clicking On Button:

After Clicking On Button:

Supported Browsers:

  • Google Chrome
  • Mozilla Firefox
  • Edge
  • Safari
  • Opera
My Personal Notes arrow_drop_up
Recommended Articles
Page :