
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Table rows Collection
The HTML DOM table rows Collection returns a collection of all <tr> elements of a table in an HTML document.
Syntax
Following is the syntax −
object.rows
Properties of rows Collection
elements in the collection in an HTML document.
Property | Explanation |
---|---|
length | It returns the number of <tr> elements in the collection in an HTML document. |
Methods of rows Collection
element from the collection element from the collection. element from the collection
Method | Explanation |
---|---|
[index] | It returns the specified index <tr> element from the collection. |
item(index) <tr> | It returns the specified index <tr> element from the collection. |
namedItem(id) | It returns the specified id <tr> element from the collection |
Let us see an example of HTML DOM table rows Collection −
Example
<!DOCTYPE html> <html> <style> body { color: #000; background: lightblue; height: 100vh; text-align: center; } table { margin: 2rem auto; } .show { font-size: 1.2rem; } .btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem auto; } .show { font-size: 1.2rem; } </style> <body> <h1>DOM Table rows Collection Demo</h1> <table border="2"> <thead> <tr> <th>Name</th> <th>Roll No.</th> </tr> <thead> <tbody> <tr> <td>John</td> <td>071717</td> </tr> <tr> <td>Jane</td> <td>031717</td> </tr> </tbody> </table> <button onclick="get()" class="btn">Get Number of Rows</button> <div class="show"></div> <script> function get() { var table = document.querySelector('table'); document.querySelector('.show').innerHTML = 'Number of rows : ' + table.rows.length; } </script> </body> </html>
Output
Click on “Get Number of Rows” button to get the number of <tr> elements from the collection.
- Related Articles
- HTML DOM Table tBodies Collection
- HTML DOM links Collection
- HTML DOM Anchor Collection
- HTML DOM embeds collection
- HTML DOM forms collection
- HTML DOM scripts Collection
- HTML DOM Datalist options Collection
- HTML DOM Images Collection Property
- HTML DOM Textarea rows Property
- HTML DOM Table Object
- HTML DOM Table caption Property
- HTML DOM Table createCaption() Method
- HTML DOM Table createTFoot() Method
- HTML DOM Table createTHead() Method
- HTML DOM Table insertRow() Method

Advertisements