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/