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 3594450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:42:54+00:00 2026-05-18T19:42:54+00:00

I am trying to write a context menu option for a page of mine.

  • 0

I am trying to write a context menu option for a page of mine.
Basically a div is right-clicked, an options menu pops up which can be used to perform tasks.

My problem is trying to find the original element which triggered everything (ie the div that was right-clicked).

My jQuery code is more or lesS:

//this is what displays the context menu
$('.outfeedPosition').bind("contextmenu", function (e) {
    $('#contextMenu').css({
        top: e.pageY + 'px',
        left: e.pageX + 'px'
    }).show();

    //'this' is the element which was clicked by the user.
    alert($(this).attr('id'));

    return false;
});



//this is the contextMenu's button handler.
$('#ctxDelete').click(function () {
    alert('delete was clicked, but i dont know by which element - so I dont know which one to delete');
});


<div id="contextMenu">
    <ul>
        <li><a id="ctxInsert" href="#">Insert</a></li>
        <li><a id="ctxEdit" href="#">Edit</a></li>
        <li><a id="ctxDelete" href="#">Delete</a></li>
    </ul>
</div>

—
So – I can see what element created the event when the initial right-click happens.
But not when the menu item is clicked.

I was working on fumbling something together by writing the element out to a hidden textbox when it is right-clicked, then reading it when one of the options is clicked, then removing it when the menu closes.
Doesn’t seem like the ideal approach though – and I feel like i’m missing something basic.

Hope you see what I am trying to do.
I can post a more complete example on request.

  • 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-05-18T19:42:55+00:00Added an answer on May 18, 2026 at 7:42 pm

    You could consider using the jQuery data storage methods.

    In your context menu code you can put:

    $('.outfeedPosition').bind("contextmenu", function (e) {
        $('#contextMenu').css({
            top: e.pageY + 'px',
            left: e.pageX + 'px'
        }).show();
    
        //Store the item that was clicked 
        $("#contextMenu").data('originalElement', this);
    
        return false;
    });
    

    Then when you want to reference the element that initiated the click, you can just do this:

    $('#ctxDelete').click(function () {
        var originalElement = $("#contextMenu").data('originalElement');
        alert('delete was clicked by ' + originalElement.id );
    });
    

    And put originalElement in the jQuery function $() to access the jQuery goodness. It doesn’t matter where you put the data, since any DOM element can have data associated to it. You can store anything – in the example code above, I store the HTMLElement raw (not jQueryified) but you can store that too if you want.

    See here for a little example: http://www.jsfiddle.net/jonathon/sTJ6M/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a menu option in which a user can select
I am trying to write a small program, which would read the context of
I am trying to write text using a Core Graphics context. I can do
I am trying to write code for a task form which shows the task
I am trying to create custom function for Main Nav menu where I can
I'm trying to implement a design for a menu on a web page, but
I'm trying to write a program that can password protect individual folders, but I'm
I am trying to create a semi transparent div & write text on top
I'm trying to write an embedded ( NOT web, not enterprise ) content management
I'm trying to put together a fun 'contest' of sorts. Developers will write a

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.