Get attribute on right-click with a jquery plugin
I got a problem here with a jQuery Plugin.
I want to get the attribute "photoId" from the image which the contextmenu has been called on so I can put an option in the menu like 'Delete (photoId)'.
In other words: I right-click on .imgPrev (see html below), I want the attribute photoId to be used in the menu.
Here is the plugin: jQuery ContextMenu Plugin
Code:
$('.imgPrev').contextMenu(menu,{beforeShow: function() {
开发者_Python百科 alert($('.imgPrev').attr('photoId'));
return true;
}});
Images are like :
<div class="imgPrev"><img str="..." photoId="541"></div>
old question however below is the solution for anyone else who might have to deal with this issue
You need to replace .imgPrev selector with this.target
$('.imgPrev').contextMenu(menu,{beforeShow: function() {
alert($('.imgPrev').attr('photoId'));
return true;
}});
with
$('.imgPrev').contextMenu(menu,{beforeShow: function() {
alert($('this.target').attr('photoId'));
return true;
}});
精彩评论