jQuery Sortable Move UP/DOWN Button

前端 未结 3 547
一向
一向 2020-12-13 09:41

I currently have a jQuery sortable list working perfectly. I am able to move the \'li\' elements around. However, how can I make a button to move a specific \'li\' element u

3条回答
  •  醉梦人生
    2020-12-13 10:20

    If you have following html code:

    
    
    
    • line_1
    • line_2
    • line_3

    I assume you have allready something to mark each lis, so following I assume the marked lihas the class markedLi; Following code should in theory move that element up or down (totally untested off course):

    $('#myButtonUp').click(function(){
      var current = $('.markedLi');
      current.prev().before(current);
    });
    $('#myButtonDown').click(function(){
      var current = $('.markedLi');
      current.next().after(current);
    });
    

提交回复
热议问题