开发者

jQuery - accessing an item's ID on double click

This should be an easy one, but through all the research I've done on the net I just can't seem to find the solution!

I've currently got a sortable list using .sortable, and then a .bind event with a double click, with the bind event as follows:

$("#controlContainer").sortable({  
   blah blah  
})  
.bind('dblclick', function(event) {  
    alert($(event.eventData).attr('id'));  
});

My issue is the fact that the above doesn't work, I need to get the ID of whichever e开发者_Go百科lement has been double clicked, but can't find a way of accessing it.

Anyone with any solution? Would be greatly appreciated.


Try changing event.eventData to event.target.

.bind('dblclick', function(event) {  
    alert($(event.target).attr('id'));  
});


Try event.target:

alert(event.target.id);

event.data is for accessing the data you pass to to bind.

Example:

.bind('click', {foo: 42}, function(event) {
    alert(event.data.foo);
});


Try

alert($(this).attr('id'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜