I was reading Learning jQuery 1.3 (Jonathan Chaffer and Karl Swedberg) and while sorting table, they used .get()
before calling .sort()
, and said
we need to transform jQuery objects into array of DOM nodes. Even though jQuery objects act like arrays in many respects , they don't have any of the native array methods available, such as .sort().
Code:
$("#sort").click(function() {
var posts = $("#posts_div .post");
posts.sort(function(a, b) {
return ($(a).text()) > ($(b).text());
});
$.each(posts, function(index, post) { $("#posts_div").append(post); });
});
So I tried to do it without using .get()
, but surprise it worked even without .get()
with latest jQuery, but didn't work with 1.3
So made some fiddles to make it clear
**Not working without .get()
jquery 1.2.6 **
Working with .get()
jquery 1.2.6
Working without .get()
jquery 1.7.2
Working with .get()
jquery 1.7.2
So obviously earlier jQuery objects didn't used to have .sort()
function same as Javascript arrays? But now they have..
So my question is what are the functions the jQuery objects not support yet, so we can keep in mind to convert to Javascript arrays, before use??