Felix, not to worry, there's nothing wrong at all with using .length - and
it is obviously faster than a function call.
 
In the earliest versions of jQuery, the jQuery object was not an array, but
had a private array object that you accessed using .get(n) and .size(). The
only reason those functions still exist is for compatibility with old code.
 
There's no reason at all to stick with .get(n) and .size() now that the
array-like jQuery object allows the simpler and more efficient [n] and
.length.
 
-Mike


  _____  

From: Felix Geisendörfer 

Sean, Mike: I agree with your notion that learning that the jQuery object is
array-like (It'd be cool if it was a real array and .push / .sort would work
on it) is very worthwhile. I knew that when I initially stumbled across the
problem and knew that doing it via '.length' was one solution. I was only
confused if it was the right way or could lead to undesired results as I was
new to jQuery at this point and I didn't find it mentioned anywhere in
specific. That's where my notion of an 'exists()' function could be useful
comes from. But it's probably just something that should be put in the
manual somewhere (if it isn't already in there and I missed it).

-- Felix

--------------------------
My Blog: http://www.thinkingphp.org
My Business: http://www.fg-webdesign.de 


Sean Catchpole wrote: 


I believe that learning jquery returns an array like object is more 
useful than creating a .exists() function. 

~Sean 



Reply via email to