Question

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...

Was it helpful?

Solution

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/

OTHER TIPS

Try replacing this part:

pbLIs.eq(0).appendTo(pbUL); 
pbLIs = $('li'); // not good...

with this:

pbLIs = pbLIs.eq(0).appendTo(pbUL); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top