开发者

Get attribute on right-click with a jquery plugin

开发者 https://www.devze.com 2023-04-05 13:17 出处:网络
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)\'

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;
            }});
0

精彩评论

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

关注公众号