Ron
Ron

Reputation: 4095

jQuery move element to end but keep variable updated

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

Answers (2)

SeanCannon
SeanCannon

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

Lee Meador
Lee Meador

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

Related Questions