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 8311957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:59:26+00:00 2026-06-08T19:59:26+00:00

I am trying to setup a nested table function. So within the function I

  • 0

I am trying to setup a nested table function. So within the function I am passing a selected element and I want to select only the children/direct-descendants td/tr of that table and NOT the nested table’s td/tr elements. Here is a little example that I setup.

<table class="top">
    <tr>
        <td>1</td>
        <td>2</td>
    </tr>
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
    <tr>
        <td>5</td>
        <td>
            <table class="nested">
                <tr>
                    <td>1</td>
                    <td>2</td>
                </tr>
                <tr>
                    <td>3</td>
                    <td>4</td>
                </tr>
                <tr>
                    <td>5</td>
                    <td>4</td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<div id="results"></div>

and the jQuery / Javascript to go with it…

var tbl = $(".top");
var r = $("div#results");

$(r).html("");

$(r).append("var tbl = $(\".top\")</br>")

$(r).append("$(tbl).find(\"td\").length:" + $(tbl).find("td").length.toString() + "</br>");

$(r).append("$(\"td\", tbl).length: " + $("td", tbl).length.toString() + "</br>");

$(r).append("$(tbl).children(\"tbody\").children(\"tr\").children(\"td\").length: " + $(tbl).children("tbody").children("tr").children("td").length.toString() + "</br>");

The results are as follows…

var tbl = $(“.top”) (to simulate the passed selector)

$(tbl).find(“td”).length:12 (selects ALL td elements)

$(“td”, tbl).length: 12 (selects ALL td elements, same as above)

$(tbl).children(“tbody”).children(“tr”).children(“td”).length: 6 (selects the proper elements, but the jQuery chain seems too long and strict for what I want to do)

Any help to find the proper selector for the children elements of the top level table is much appreciated! Thanks!

Update: here is the jsFiddle.

  • 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-06-08T19:59:28+00:00Added an answer on June 8, 2026 at 7:59 pm

    Working fiddle using direct descendant (>) selector: http://jsfiddle.net/3T9sN/

    $(function(){
        var rows = $(".top > TBODY > TR");
        alert( "Number of rows: " + rows.length );
    
        var cells = $(".top > TBODY > TR > TD");
        alert( "Number of cells : " + cells.length );
    });​
    

    Of course, you can reuse some of the contexts here to make the query more efficient, such as:

    var tbody = $(".top > tbody");
    
    // using children() method
    var rows = tbody.children( "TR" );
    
    // using selector context
    var cells = $( "> TR > TD", tbody );
    
    alert( "Number of rows: " + rows.length );
    alert( "Number of cells : " + cells.length );
    

    Fiddle: http://jsfiddle.net/3T9sN/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup a CSS style to highlight a table cell in a
I am trying to get nested viewflippers set up with the following setup Top_ViewFlipper
I'm trying to get a better setup working for updating a model with nested
Given a function, I'm trying to find out the names of the nested functions
I'm trying to setup a UITableView for displaying nested threaded items. I'm using Core
I'm trying to setup a nested form and the main thing I can't get
Trying to setup a personal image upload/downloader webpage. I've viewed the msdn article on
Trying to setup a CodeIgniter based project for local development (LAMP stack), and once
Trying to setup some validation on the add to cart button for the dropdown
Trying to setup and get going with the RestKit library for a cocoa project

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.