Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8607751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:26:15+00:00 2026-06-12T03:26:15+00:00

I have a jquery function to display a menu on right click event. I

  • 0

I have a jquery function to display a menu on right click event.
I wish to access an object from the parent function inside the callback function.

Am using following JQuery plugin to get the context menu.

Here is the code:

function OnContextMenu() {

     //alert(key + ' ' +this.Node.Content);
     var localNode = this.Node;
     alert(localNode.Content); //CORRECT NODE VALUE GETS ALERTED

        $.contextMenu({
            selector: '.Container', 
            callback: function(key, options) {
                var m = "clicked: " + key;
                 alert(localNode.Content); //ALWAYS PRINTS THE VALUE OF THE VERY FIRST NODE THAT WAS CLICKED. 
                // window.console && console.log(m) || alert(m); 
            },
            items: {
                "edit": {name: "Edit", icon: "edit"},
                "cut": {name: "Cut", icon: "cut"},
                "copy": {name: "Copy", icon: "copy"},
                "paste": {name: "Paste", icon: "paste"},
                "delete": {name: "Delete", icon: "delete"},
                "sep1": "---------",
                "quit": {name: "Quit", icon: "quit"}
            }
        });
    }

As you can see I am storing the value in a variable:

var localNode = this.Node;

and using this variable inside the callback function.
Peculiar thing about this is, the alert(localNode.Content); inside the callback gives correct value when the menu is clicked the very first time. After that even though the alert of the outer function gives different values correctly, the inner callback function keeps displaying the same old value as that of the first time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:26:16+00:00Added an answer on June 12, 2026 at 3:26 am

    Feeling quite stupid right now cause I was missing a very simple thing here.
    I was able to resolve this issue by declaring variable outside the function as in by using a global variable.

    Below is the change:

     var localNode;
    
     function OnContextMenu() {
    
     //alert(key + ' ' +this.Node.Content);
     localNode = this.Node;
     alert(localNode.Content); //CORRECT NODE VALUE GETS ALERTED
    
        $.contextMenu({
            selector: '.Container', 
            callback: function(key, options) {
                var m = "clicked: " + key;
                 alert(localNode.Content); //ALWAYS PRINTS THE VALUE OF THE VERY FIRST NODE THAT WAS CLICKED. 
                // window.console && console.log(m) || alert(m); 
            },
            items: {
                "edit": {name: "Edit", icon: "edit"},
                "cut": {name: "Cut", icon: "cut"},
                "copy": {name: "Copy", icon: "copy"},
                "paste": {name: "Paste", icon: "paste"},
                "delete": {name: "Delete", icon: "delete"},
                "sep1": "---------",
                "quit": {name: "Quit", icon: "quit"}
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery menu plugin. initialy the plugin is operated with right click.
I have the following code: $(document).ready(function() { // Manage sidebar category display jQuery(#categories >
I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
I have to retrieve a list of menu item from a database and display
I have a slide down menu that uses the following jquery. $(document).ready(function() { //
I have a jQuery menu that is represented with these paramaters: <script type=text/javascript> jQuery(document).ready(function(){
I have this: <script type=text/javascript> jQuery(document).ready(function(){ jQuery('#menu-main-menu li a').after('<p class=separator>/</p>'); jQuery(.textwidget a[href^='http://']).attr(target,_blank); }); </script>
I have the following jquery that I wrote: $(document).ready(function(){ $('div.contentTxtBox#home').addClass('current').show(); $('a.menu').click(function() { $('div.contentTxtBox.current').hide(slide, {
I have this jquery function that works, except I need to add something. I
I have a jQuery function that replaces thumbnails with the main image. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.