Bug Tracker

Modify

Ticket #3407 (closed bug: invalid)

Opened 5 years ago

Last modified 4 years ago

Multiple :gr do not work as expected

Reported by: greggreenhaw Owned by:
Priority: major Milestone: 1.3
Component: selector Version: 1.2.6
Keywords: gt:,selctors Cc:
Blocking: Blocked by:

Description

running this: $('table tr:gt(1) td:gt(2)').css('background-color','white');

on a table will skip on the first 2 columns on the first row and not on each additional row.

Change History

comment:1 Changed 5 years ago by scott.gonzal

  • Status changed from new to closed
  • Resolution set to worksforme

This is the correct behavior. The selector says find all tables, then fine all rows, and limit to everything after the first row, then find all data cells and limit to everything after the first two cells.

To accomplish what you want, you need to do:

$('table').each(function() {
    $(this).find('tr:gt(1)').each(function() {
        $(this).find('td:gt(2)').css('background-color', 'white');
    });
});

comment:2 Changed 5 years ago by greggreenhaw

  • Status changed from closed to reopened
  • Resolution worksforme deleted

I disagree since its in the selector, I think it should scoped in the context of the parent "tr" selector, thus for each row greater than 1 cells greater than 2, for each row. Otherwise I would just do an array _slice or someting or a simple filter as a nested function.

comment:3 Changed 4 years ago by dmethvin

  • Status changed from reopened to closed
  • Resolution set to invalid

Scott's right. Perhaps you wanted something like :not(:first-child) instead?

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.