[Solved] html tag transfer it up or down use jquery and ajax when click [closed]


Add classes to your up/down links:

<div id="menu">
    <div id="line1"> A <a class="up">up</a> <a class="down">down</a></div>
    <div id="line2"> B <a class="up">up</a> <a class="down">down</a></div>
    <div id="line3"> C <a class="up">up</a> <a class="down">down</a></div>
    <div id="line4"> D <a class="up">up</a> <a class="down">down</a></div>
    <div id="line5"> E <a class="up">up</a> <a class="down">down</a></div>
</div>

Add CSS to hide unused first and last link:

#menu > div:first-child a:first-child,
#menu > div:last-child  a:last-child { display: none; }

jQuery:

$('#menu').on('click', 'a', function() {
    var divs = $('#menu > div');
    var p = $(this).parent();
    var pos = p.index();

    if($(this).hasClass('up')) {
        p.insertBefore(divs.eq(--pos));
    }
    else if($(this).hasClass('down')) {
        p.insertAfter(divs.eq(++pos));
    }
});

http://jsfiddle.net/samliew/P4Xaf/

6

solved html tag transfer it up or down use jquery and ajax when click [closed]