i want the draggable object to revert back to its original position when i click a button. i used \'destroy\' option but it doesnt seem to work. it disables the dragging but
function revertable($drag){
$drag.data({ top: $drag.css('top'), left: $drag.css('left') })
$('.'+$drag.attr('id')+'.revert').data({ revert: '#'+$drag.attr('id') })
.on('click',function(){
var $rev = $( $(this).data('revert') );
$rev.css({ top: $rev.data('top'), left: $rev.data('left') });
})
}
// simply call the function in the create event
var $drag = $('#my_draggable'); //your element
$drag.draggable({
create: revertable($drag)
});
//test it: change the top/left values, refresh, click the button to see it work.
Drag Me Around
...tested, should work for any element (requires jquery 1.7 for .on() function)