Reputation: 4095
how can I move element to end but keep the variable updated without traversing again?
var pbUL = $('ul');
var pbLIs = $('li');
pbLIs.eq(0).appendTo(pbUL);
pbLIs = $('li'); // not good...
simple problem - probably simple soluction, but I have no Idea how to solve...
Upvotes: 0
Views: 190
Reputation: 77966
Why not this:
(function( $ ) {
$.fn.shift = function() {
var bottom = this.get(0);
this.splice(0,1);
return bottom;
};
})( jQuery );
var arr = $('li');
arr.push(arr.shift());
Demo: http://jsfiddle.net/m6Pf6/
Upvotes: 1
Reputation: 12985
Try replacing this part:
pbLIs.eq(0).appendTo(pbUL);
pbLIs = $('li'); // not good...
with this:
pbLIs = pbLIs.eq(0).appendTo(pbUL);
Upvotes: 0