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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:50:09+00:00 2026-05-29T10:50:09+00:00

How do I retrieve the td’s in a tr where the td index (within

  • 0

How do I retrieve the td's in a tr where the td index (within the row) is not 1 or 2? That is, I want to skip the first two columns. The following code gets the job done but is there a better way to do it? I’m thinking (td eq(0) || eq(1)) something like that.

  $("#time-entry tr").each(function () {
            var trId = $(this).attr('id');
            $(String.format("#{0} td input[id^=txt]", trId)).each(function () { //rewrite
                var tdIndex = $(this).index();
                if(tdIndex != 1 && tdIndex != 2) {

                }
            });
        });
  • 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-29T10:50:10+00:00Added an answer on May 29, 2026 at 10:50 am

    I’d like to suggest an alternative approach, completely ignoring how to do things by index (which you can already see how to do from the other answers) and instead try to solve the underlying problem in a simple and maintainable way.

    You said in a comment that what are really trying to do is add up some textboxes and put the row total in the last column, so to me it makes sense to select them directly rather than selecting the containing td elements. You did note that the first two columns have textboxes that you don’t want to select but we can easily allow for that.

    Rather than messing around with column indexes, which means you’ll have to change your code if you later insert/delete/re-order columns, I suggest you give a common class to the elements you want to add up and then another class to the (last column) row-total elements. So something like this in your markup:

    <tr>
       <td><input></td>
       <td><input></td>
       <td><input class="addup"></td>
       <td><input class="addup"></td>
       <td><input class="addup"></td>
       <td><input class="total"></td>
    </tr>
    

    (Obviously you’ll have other attributes but that was just a sample to show the classes.)

    Then the JS is really simple:

    // process each row
    $("tr").each(function() {
       var total = 0;
       // select all "addup" elements in the current row
       $(".addup", this).each(function() {
          // add to the row total, converting to a number with
          // the unary plus operator. TODO: add some validation to be
          // sure the user actually entered numeric data
          total += +this.value;
       });
       // display the total
       $(".total", this).val(total);
    });
    

    If you insert extra columns in the middle that shouldn’t be added, no problem: without the “addup” class they’ll be ignored automatically.

    Note also that your code: $(String.format("#{0} td input[id^=txt]", trId)) seems to be trying to use a C# method in the middle of your JavaScript, which won’t work. But you don’t need to worry about trying to select elements based on the current row’s id because within the $("tr").each() handler the keyword this will refer to the current row so you can pass that to the $() function as context for the selection. So like $(".addup", this) as shown above.

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

Sidebar

Related Questions

I want to retrieve the email address from the table and using that to
I want to retrieve the HTML code of a link (web page) in PHP.
I want to retrieve a row from a MySQL database which returns a row,
To retrieve the Android camera size I've used the following code: camera=Camera.open(); Parameters params
To retrieve data from ActiveDirectory I used the following code: SPSecurity.RunWithElevatedPrivileges(delegate() ( var currentDirectory
I retrieve .jpgs from my server and load them within my as3 app. I
I would like to retrieve the ethernet address of the network interface that is
To retrieve values which are not in db, I use Common Table Expression like
I would like to retrieve the cpu and ram usage at that point for
I want to retrieve the data contained in a text file (from a given

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.