There is an undocumented feature of jQuery where destructive methods (like
eq()) will accept a callback function as a second argument. That function
will have the new selection as 'this', but other methods on the chain will
still be using the origonal selection. i.e. $("div").eq(n,function(){
this.hide(); }).eq(m,function(){ this.show() });
Blair
On 11/24/06, Matt Stith <[EMAIL PROTECTED]> wrote:
i think element[n] would be the best, but im no expert.
On 11/23/06, George Adamson <[EMAIL PROTECTED]> wrote:
>
> If your jquery results array is in a variable (to reuse it instead of
> re-querying over and over again) then what is the best way to get the
nth
> item from it *without modifying the array* ?
>
> For instance the following would cause the myElements variable to end up
> containing only one item!
> var myElements = $("DIV");
> var nthElement = myElements.eq(n);
>
> If it wasn't for the variable the options might be:
> - $("DIV").eq(n)
> - $("DIV:eq(n)")
> - $("DIV")[n] (this one is ok if you want the html element, but I
need it
> wrapped as a jquery object)
>
> These seem to be the possible solutions: (but which is most efficeient?
The
> third one looks simplest)
> - myElements.eq(n).each(function(){ ...do something with the nth item
> here...}).end()
> - $(":eq(n)", myElements)
> - $(myElements[n])
>
> Many thanks. George
> --
> View this message in context:
>
http://www.nabble.com/Correct-way-to-get-the-nth-item--tf2694862.html#a7515463
> Sent from the JQuery mailing list archive at Nabble.com.
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/