Domanda

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

È stato utile?

Soluzione

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/

Altri suggerimenti

Try replacing this part:

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

with this:

pbLIs = pbLIs.eq(0).appendTo(pbUL); 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top