You can use 'insertBefore' to do this very easily.

For example:

$(document).ready(function(){
    $('.smallDiv').click(function(){

        $(this).insertBefore($(this).prev());

    });
});

This will swap a 'smallDiv' element up by one when you click it. If it
is already the first one, $(this).prev() has length 0 so it doesn't do
anything.

Just change it to suit your needs.

Eg:

function shiftUp(obj) {
     $(obj).insertBefore($(obj).prev());
}

On Feb 13, 12:26 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> Let's say I have a large DIV with class "largeDiv" and inside it, a
> bunch of smaller DIVs, each with its own unique ID and class
> "smallDiv".  Given an arbitrary DIV with class "smallDiv", if I want
> it to switch places with the DIV immediately above it, how do I
> achieve the switch?  Keep in mind that it may already be the top DIV
> in the list.
>
> Thanks, - Dave

Reply via email to