Jquery delete element by double click
Jquery drag and drop question
I want to delete some elements that are inside a div container. My script is like this : i drag the element into #deleteArea and the element is out. The 开发者_高级运维script : $("#deleteArea").droppable
({
drop: function(event, ui) {
alert('in');
deleteImage(ui.draggable,ui.helper);
},
over: function() {
$(this).css('backgroundColor', '#cedae3');
},
out: function() {
$(this).css('backgroundColor', '#ffffff');
},
});
and
function deleteImage($draggable,$helper)
{
params = 'id=' + $draggable.attr('id');
$.ajax({
url: 'delete.php',
type: 'POST',
data: params,
success: function(msg){
}
});
$helper.effect('transfer', { to: '#deleteArea', className: 'ui-effects-transfer' },500);
$draggable.hide();
}
Now i want to remove elements just by double click. I try starting from the script above this little code :
$('.produse').dblclick(function(event, ui) {
alert('in');
deleteImage(ui.draggable,ui.helper);
});
but i recive "ui is undefined" and i dont know what to do. please help
You are not passing parameters to the click handler correctly.
In this piece of code:
$('.produse').dblclick(function(event, ui) {
alert('in');
deleteImage(ui.draggable,ui.helper);
});
you have not declared the parameters to the anonymous function appropriately. If you look at the jQuery doc for .dblclick()
, there are two ways of calling it:
.dblclick(handler(event))
or
.dblclick([eventData,] handler(event))
You are using neither of those.
If you want to pass some data to the dlbclick handler, it would work like this:
$('.produse').dblclick({uiData: ui}, function(event) {
alert('in');
deleteImage(event.data.uiData.draggable, event.data.uiData.helper);
});
You can see it in action here: http://jsfiddle.net/jfriend00/NUU8s/
精彩评论