1

I wrote code. when you click on the button function is called up, which will raise the div up one position over another div, and the same with the Down just down Do you know how to do it ? http://jsfiddle.net/WmbmF/15/

<button type="submit" class="button" id="addk">Add div</button>
 <div class="body" style="float: left;">

and

var RL;
RL = 0;
$("#addk").click(function () {
       RL = RL + 1;
        RN = "Tekst" + RL;
         $("<div id='" + RN + "' class='we' > " +
          "<B>Kon" + RL +"</B>" +
           "<button type='submit' class='button'  onclick='Add(" + RN + ");' >AddNext</button>" +
           "<button type='submit' class='button'  onclick='Close(" + RN + ");' >Close</button>" +
           "<button type='submit' class='button' onclick='Up(" + RN + ");' >Up</button>" +
           "<button type='submit' class='button' onclick='Down(" + RN + ");' >Down</button><br />" +
           "<br />"  + "<input type='text'>" + "<br /><br />" + '</div>').

         appendTo(".body");
    });
function Close (){
 $("#" + body.id + "").hide();
}
function Up (we){
//??
}
function Up (we){
//?
}
Pete D
  • 777
  • 5
  • 15

2 Answers2

0

Don't know if this is what you want exactly but you could try this:

$('button').click(function () {
    if ($(this).hasClass('up')) {
        $(this).closest('div').insertBefore($(this).closest('div').prev());
    } else {
        $(this).closest('div').insertAfter($(this).closest('div').next());
    }
});

http://jsfiddle.net/F8D7d/

Andy
  • 29,707
  • 9
  • 41
  • 58
0

This way doesn't seem very user friendly, what happens if there are 100 items to move up and down? I think a better way to achieve this would be to have a sortable list instead:

http://jqueryui.com/sortable/#default

Terry Kernan
  • 746
  • 5
  • 12