jQuery UI draggable - Custom data disappears
I'm having a weird problem with using jQuery UI Draggable and setting custom data.
My code:
$('.drag')
.data('foo', 'bar')
.draggable({
stop: function(event, ui) {
var foo = $(this).data('foo');
alert(foo); // alerts 'undefined'
}
});
It seems it's losing all it'开发者_StackOverflow中文版s when dragging (console.log'ing $(this).data inside stop() shows an empty object). Is
Any ideas?
EDIT:
Silly silly me, I was doing a $(ui.draggable).remove() inside the drop-function of the droppable i was dragging the object into, so the object was removed before it could get any data. You would think that the draggable's 'stop'-event would be called before the droppable's 'drop' event though...
Are you using jQuery UI 1.7.2 ?
I test it and every thing is working fine
check this link on JSBin
click preview to run the code.
精彩评论