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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:15:56+00:00 2026-05-22T21:15:56+00:00

I know this question has been asked a lot but there is really no

  • 0

I know this question has been asked a lot but there is really no definite answer that I can find.
Here is my code. Basically I have everything set up. I’m just lost on where to get the rows of a table by index. I’ve tried the .index function but I that’s not working. I’m trying to do something like $('#pkgLineTable').index(i).addClass('row_selected');

But that’s not working correctly. Any help would be great. Thank you very much.

var lastSelected;

$('#pkgLineTable tr').live('click', function(event) {         

    var tableRow = $(this).closest("tr").prevAll("tr").length + 1;      
    if ($(this).hasClass('row_selected')) {
        $(this).removeClass('row_selected');       
    }
    else {           
        $(this).addClass('row_selected');         
    } 

    if (event.shiftKey) { 
        var table = $('#pkgLineTable');        


        var start = Math.min(tableRow, lastSelected);
        var end = Math.max(tableRow, lastSelected);                 

        for (var i = start; i < end; i++) {
            //$(this).parent().parent().addClass('row_selected'); 
        }

    } else {        

        lastSelected = $(this).closest("tr").prevAll("tr").length + 1;
    }

My start and end values are correct. If you select the 2 row and the 5 row you get back 2 and 5. It then iterates 2 – 5. I need to add a class to the rows 2 – 5.

Edit I used this:

    for (var i = start; i < end; i++) {
            $('#pkgLineTable').each(function() {
                $(this).find("tr").eq(i).addClass('row_selected');    
            });
        }

That’s probably not the best way to do it.

  • 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-22T21:15:57+00:00Added an answer on May 22, 2026 at 9:15 pm

    instead of

    for (var i = start; i < end; i++) {
      //$(this).parent().parent().addClass('row_selected'); 
    }
    

    use

    table.find('tr:gt('+(start-1)+'):lt('+(end)+')').addClass('row_selected');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked before but I really couldn't find anything
I know this question has been asked/answered but I can't find it for the
I know this question has been asked many times before but I can't find
I know this question has been asked before, but there was no clear answer.
So I know this is a question that has been asked a lot, but
I know this question has been asked 100x but I can't seem to find
I know this question has been asked several times, but I can't quite seem
I know this question has been asked a couple of times, but there's something
I guess this question has been asked a lot around. I know Rails can
I know this question has been asked before, but I haven't found an answer

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.