[jQuery] Re: How can the selector match the last 2 selected element.

2008-07-21 Thread chrisyue
Thanq Karl, and thank Mike Alsup too On Jul 18, 9:50 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote: > On Jul 18, 2008, at 9:22 AM, Mike Alsup wrote: > > > You could create a new selector shortcut for that case like this: > > > jQuery.expr[':'].lastx = function(a,i,m,r){return i>=r.length-m[3];}; >

[jQuery] Re: How can the selector match the last 2 selected element.

2008-07-18 Thread Mike Alsup
> You could also just use the slice() method :-) > > $('div').slice(-2); Nice!

[jQuery] Re: How can the selector match the last 2 selected element.

2008-07-18 Thread Karl Swedberg
On Jul 18, 2008, at 9:22 AM, Mike Alsup wrote: You could create a new selector shortcut for that case like this: jQuery.expr[':'].lastx = function(a,i,m,r){return i>=r.length-m[3];}; And then use it like this: var lastTwoDivs = $('div:lastx(2)'); You could also just use the slice() method

[jQuery] Re: How can the selector match the last 2 selected element.

2008-07-18 Thread Mike Alsup
> The selector can match last one elememt by using ":last", but how > about last n elements?Are there some simple way to do this? You could create a new selector shortcut for that case like this: jQuery.expr[':'].lastx = function(a,i,m,r){return i>=r.length-m[3];}; And then use it like this: v