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

  • SEARCH
  • Home
  • 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 4241932
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:22:29+00:00 2026-05-21T03:22:29+00:00

Like some existing examples I want to select only the first level of TD’s

  • 0

Like some existing examples I want to select only the first level of TD’s within a selector, the difference here is that the operation is on an existing selection.

Let’s say I have a table like so…

<table border=1>
<tr trid="1">
   <td>cell 1</td>
   <td>cell 2</td>
   <td>cell 3</td>
</tr>
<tr trid="2">
   <td>cell 1</td>
   <td>

       <table border=1>
        <tr>
           <td>cell 1</td>
           <td>cell 2</td>
           <td>cell 3</td>
        </tr>
        <tr>
           <td>cell 1</td>
           <td>cell 2</td>
           <td>cell 3</td>
        </tr>
       </table>

   </td>
   <td>cell 3</td>
</tr>
<tr trid="3">
   <td>cell 1</td>
   <td>cell 2</td>
   <td>cell 3</td>
</tr>
</table>

I want to initially traverse this particular table row by row. I only want to traverse the rows that have a custom attribute of “trid”.

I managed to get this far…

    $('tr[trid]').each(function(index)
    {
        //gets properties of TR here

        $('td',this).each(function(index)
        {
            $(this).css('background-color', 'red'); //turn my cells red
        });

    });

Now this works but I only want the first level of Cells. So I want the TD loop to ignore the second level of td’s.

I know if the outer loop used tr[trid]>td this would work however I then skip an important part of the loop. Is there syntax I can use to operate like this on the existing selection, i.e. ensuring the parent of the selected td has the tr[tabid].

This is quite particular in that I cannot add new styles or change the existing HTML in anyway. Also the order of the JQuery loop is also important since it outputs as it runs and needs to retain it’s sequence.

Thanks 🙂

  • 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-21T03:22:29+00:00Added an answer on May 21, 2026 at 3:22 am

    Instead of

    $('td',this).each(function(index)
    

    use

    $(this).children('td').each(function(index)
    

    example: http://jsfiddle.net/gaby/tz2jt/1/


    or the more cryptic (but you get the idea)

    $('> td',this).each(function(index)
    

    example: http://jsfiddle.net/gaby/tz2jt/

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

Sidebar

Related Questions

For some reason I can only find plugin examples that are directly bound to
I would like to implement some live elements to an existing PHP app. So
I would really like some advice here, to give some background info I am
It seems like some tables are inheriting styles that they shouldn't. I have a
I would like some container that I can very efficiently append a variable amount
I would like some sugestion on how to design a table that gets like
I want to create an extra radio button with some choices inside an existing
I want to get a Stream from some arbitrary position in an existing file,
I want to do classpath scanning using some existing library. extcos seems to be
Lets say I am using some existing java library, and I only got .class

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.