Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:30:27+00:00 2026-05-30T07:30:27+00:00

How do I get the immediate children when searching for a particular element? For

  • 0

How do I get the immediate children when searching for a particular element? For example, I want to get the tr elements for the table t1.

    <table id="t1" bgcolor="yellow">
        <tbody>
            <tr>
                <td>This is Cell 1</td>
                <td>This is Cell 2</td>
            </tr>
            <tr>
                <td>This is Cell 3</td>
                <td>
                    <table id="t2" bgcolor="red">
                        <tbody>
                            <tr>
                                <td>This is Cell 1</td>
                                <td>This is Cell 2</td>
                            </tr>
                            <tr>
                                <td>This is Cell 3</td>
                                <td>This is Cell 4</td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>

I tried this:

'Count = ' + $('#t1 tbody').children('tr').length;

However, I get a count of 4, I don’t understand why?

Here is a full example:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:30:28+00:00Added an answer on May 30, 2026 at 7:30 am

    Use:

    'Count = ' + $('#t1 > tbody').children('tr').length;
    //  or: $("#t1 > tbody > tr").length
    //  or: $("#t1")[0].rows.length; // In this case, equal to previous code.
                                     // Warning: This also includes the rows from
                                     //  the <thead> and <tfoot> sections.
    

    Your current code shows 4, because you have got two <tbody> elements in the table #t1:

    <table id="t1" bgcolor="yellow">           <-- #t1
        <tbody>                                <--- tbody
            <tr> ... </tr>                     <----- Child 1
            <tr> ...                           <----- Child 2
                        <tbody>                <--- tbody (unexpected?)
                            <tr> ... </tr>     <----- Child 3
                            <tr> ... </tr>     <----- Child 4
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to get the # of immediate children an element has, and then
how can i get immediate parent of a given element ? $(e.target).parent() ?
A quick question.. what's the JAVASCRIPT statement to get the immediate children of a
I want to be able to expand or collapse all children of a particular
I'm trying to get this dynamic SQL running ( using EXECUTE IMMEDIATE ) M_SQL_STATEMENT
In Javascript, after executing a function I can immediately get the an element of
I have been trying to get this one section of my UI to immediatly
I have a structure like this: <ul id="mycustomid"> <li><a>Item A</a> <ul class="children"> <li><a>Child1 of
I want to make form submission on every onchange() form field event to get
I have a function that appends some HTML to an element. It may get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.