0

Im using JQuery Context Menu plugin.

When the document is ready, I have contextMenu for img elements

$(document).ready(function(){
    $('img').contextMenu({
        menu: 'photoMenu'
    },function(action, el, pos) {
        //some function

    });
});

I am going to add dynamically img element:

$img = $('<img />');

How to bind contextMenu for the newly created img element. It should be the same with the above? Should I create a function call it? Or there are other easy way for this?

Thanks.

1
  • Please close the question, if you got the answer...
    – Wolf
    Jan 23, 2013 at 9:10

1 Answer 1

1

Currently you are attaching your contextMenu in your document ready function. You should create the contextMenu after the image is created.

So just update your code to

$img = $('<img />');

$img.contextMenu({
        menu: 'photoMenu'
    },function(action, el, pos) {
        //some function

    });

Note: You have to make sure that you are creating the contextMenu after creating the image object.

2
  • I have existing img element when page load.
    – JR Galia
    Jan 23, 2013 at 7:15
  • In that case don't delete the current contextMenu code in $(document).ready.
    – Wolf
    Jan 23, 2013 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.