tags:

views:

76

answers:

1

How to process element excluding the first and last one. I have a table with a given number of rows. I want to trigger the rows on a click event but should not process the click if first or last row is clicked. How can I implement this?

+5  A: 

How about:

$('tr:not(:first, :last)').click(function() {
    // ...
})

?

Roatin Marth
This isn't a valid CSS selector, :not can only contain a simple selector. It seems to work in jQuery at the moment, but `tr:not(:first):not(:last)` would be the reliable way to do it.
bobince
@bobince: since 1.3 jQuery can take complex selectors in :not psuedo expressions (i.e., comma separated selectors are valid): http://docs.jquery.com/Selectors/not
Roatin Marth