HTML | DOM Table tBodies Collection

The Table tBodies collection is used for returning the collection of all the <tbody> elements in a table. The sequence of the <body> elements are sorted in the same way as their position in the source code.

Syntax

tableObject.tBodies

Properties



  • length : It is used to return the number of <tbody> elements in the collection.

Methods

  • [index] : It is used for returning the <tbody> element from the collection with a specified index.
  • item(index) : It is also used for returning the <tbody> element from the collection with a specified index.
  • namedItem(id) : It is also used for returning the <tbody> element from the collection with a specified id.

Below program illustrates the Table rows collection :
Example: Finding out the number of <tbody> elements in a table .

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>Table tBodies Collection in HTML
  </title>
    <style>
        table,
        td {
            border: 1px solid green;
        }
          
        h1 {
            color: green;
        }
          
        h2 {
            font-family: Impact;
        }
          
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
  
    <h1>GeeksforGeeks</h1>
    <h2>Table tBodies Collection</h2>
  
    <p>To return the number of <tbody
      elements in the table, 
      double-click the "Return body" button.</p>
  
    <table id="Courses" align="center">
        <caption>Courses by Geeksforgeeks</caption>
        <tbody>
            <tr>
                <td>Java</td>
                <td>Fork Java</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td>Python</td>
                <td>Fork Python</td>
            </tr>
        </tbody>
        <tbody>
            <tr>
                <td>Placements</td>
                <td>Sudo Placement</td>
            </tr>
        </tbody>
    </table>
    <br>
  
    <button ondblclick="tr()">
      Return tbody
  </button>
  
    <p id="test"></p>
  
    <script>
        function tr() {
            
            // Returning tBodies element length.
            var r =
            document.getElementById("Courses").tBodies.length;
            
            
            document.getElementById("test").innerHTML =
              r + " tbody elements are present in the table.";
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:

Before clicking the button:

After clicking the button:

Supported Browsers:

  • Apple Safari
  • Internet Explorer
  • Firefox
  • Google Chrome
  • Opera


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.