How to create a previous variable?

50 Views Asked by At

I am trying to create a drag and drop system where the old dragged-element goes back when a new one comes in, but I am having trouble making use of a previous variable. Here is the code:

//making the objects draggable
for (i = 0; i <= 9; i++) {
    $("#" + i + "individual").draggable({
        revert: true

    });
}
//creating the drop area
$(".music-player").droppable({
    drop: handleDropEvent
});

function handleDropEvent(event, ui) {
    var draggable = ui.draggable;
    var currentID = ui.draggable.attr('id');
    var current = currentID.slice(0, -10); //creating id for current draggable
    ui.draggable.draggable('option', 'revert', false);
    ui.draggable.position({
        of: $(this),
        my: 'left top',
        at: 'left top'
    });
    ui.draggable.css('zIndex', '999');

    $("p").html(previous);//using this to test if works

    var previous = current;//creating the previous variable



}

Any ideas on how to fix this problem?

0

There are 0 best solutions below