javascript - How to push item values to extreme top/bottom in selectbox? -


i researching , testing forms. far, succeeded in moving items in select box list , down 1 one following fiddle.

instance of code (to move up):

function moveup() { $("#list-box option:selected").each(function () {     var listitem = $(this);     var listitemposition = $("#list-box option").index(listitem) + 1;      if (listitemposition == 1) return false;      listitem.insertbefore(listitem.prev());   }); } 

but need move selected value, either @ extreme top in list or @ bottom. please try experiment fiddle , suggest me possible jquery tree traversal method if applies.

thanks in advance!

to move top:

    var listitem = $(this);     listitem.insertbefore(listitem.siblings().first()); 

to move bottom:

    var listitem = $(this);     listitem.insertbefore(listitem.siblings().last()); 

http://jsfiddle.net/mblase75/cyw6r/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -