> What about
>
> Array.prototype.sort.apply( $('li') );
>
> Not sue if that'll work... 
I think that could work, but it's breaking chainability so I think the 
array plugin mentioned by Jörn earlier is a better alternative. However 
since I all I need is sort(), I actually am fine with using get() that 
one time.

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


Klaus Hartl wrote:
>
> Felix Geisendörfer wrote:
>>> Felix, not to worry, there's nothing wrong at all with using .length 
>>> - and it is obviously faster than a function call.
>> I figured that by now. I think Matt was much better at explaining why 
>> I think an alternative exists() function is useful - it simply is the 
>> most intuitive thing a new jQuery user looks for. I also agree with 
>> his hasClass argument. I love the is() function, but I would have 
>> taken me a long time to find it if I my question was phrased "Who can 
>> I determine if an element has a certain class".is() is more powerful 
>> but not nearly as intuitive as hasClass would be for new users.
>>> 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.
>> I disagree. Whenever you need to sort the elements in an <ul> or 
>> something then you'll have to use the Array.sort() function, so you 
>> need to do $('ul li').get().sort(...). Here is an example of where I 
>> needed this functionality: http://bin.cakephp.org/view/1632218532
>>
>> It's not a big deal that I have to call get(), but it would be a big 
>> problem if it wasn't there!
>
>
> What about
>
> Array.prototype.sort.apply( $('li') );
>
> Not sue if that'll work...
>
>
> --Klaus
>

Reply via email to