jquery get() method , how exactly does it work?

53 views Asked by At

I need to understand the difference between the clone() and get() method, I have this code and I would like to know if the get() method creates a duplicate of the array and if I can just use the clone() method instead?

(function($){
$(document).ready(function(){
var lis = $("ol li").get().reverse();
$("ol").empty();
$.each(lis, function(i){
$("ol").append("<li>" + lis[i].innerHTML + "</li>");
});
});
})(jQuery);

1

There are 1 answers

0
rrk On

When you ask something, make sure you provide proper details, like the version of jQuery, and the HTML code used.

This works for me in the fiddle.

$(document).ready(function() {
    var lis = $("ol li").get().reverse();
    $("ol").empty();
    $.each(lis, function(i) {
        $("ol").append("<li>" + lis[i].innerHTML + "</li>");
    });
});

http://jsfiddle.net/rejithrkrishnan/19ejv9j9/

I removed (function($){})(jQuery); from your code, because you don't need both this and $(document).ready(function() {});

This answer uses jQuery 1.8.3