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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:45:02+00:00 2026-05-23T00:45:02+00:00

I have a psuedo contextual menu script on my webpage. The idea is that

  • 0

I have a psuedo contextual menu script on my webpage. The idea is that a script will check to see if the element you’re hovering over has a certain class. If it does, it sets a string variable to a certain value. This way, when ctrl is pressed, i can check the string variable content to determine which contextual menu should be un-hidden.

var cmEl = "";

$('div').live('mouseover', function(e){
    e.stopPropagation();

    var actEl = $(this);

    if (actEl.hasClass("B_Info")) {
        var cmEl = "BiP";
    } else if (actEl.hasClass("BiO")) {
        var cmEl = "BiO";
    } else if (actEl.hasClass("myOpt")) {
        var cmEl = "myOpt";
    } else {
        var cmEl = "GEN";
    }
    $("#tell").html("" + cmEl + "");

});

$(document).keydown(function(e) {
    if (e.ctrlKey) {
        if (cmEl.match('BiP')) {        
            $("#Badge_C_M").removeClass("HIDE");            
            $(this).remove();
        } else if (cmEl === "BiO") {        
            $("#Opt_C_M").removeClass("HIDE");          
        } else if (cmEl === "myOpt") {      
            $("#Count_C_M").removeClass("HIDE");            
        } else {
            $("#Gen_C_M").removeClass("HIDE");          
        }
    }
});

Via the html read-out, i can see that the variable is indeed being set to the desired values, but the latter part, that determines which menu to show, doesn’t work.

As well, my first script only checks divs, but i’d like it to check any element type; or at least divs and imgs.

  • 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-23T00:45:03+00:00Added an answer on May 23, 2026 at 12:45 am

    You’re resetting the value of cmEl in your function scope. You need to just rewrite it like this….

    if (actEl.hasClass("B_Info")) {
        cmEl = "BiP";
    } else if (actEl.hasClass("BiO")) {
        cmEl = "BiO";
    } else if (actEl.hasClass("myOpt")) {
        cmEl = "myOpt";
    } else {
        cmEl = "GEN";
    }
    

    Now your global variable cmEl is being set, thus can be read in your subsequent .keydown function. If you want to read different elements, you can bind them like this….

    $('div, img, input').mouseover(function(e){ ...code... });
    

    hope this helps.

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

Sidebar

Related Questions

I have a windbg script that I plan on assigned to run via a
I have a page that has a form on it where the user can
I have developed a psuedo 3D carousel for the iPhone that looks pretty much
I have a presenter class that will spawn a new presenter and view upon
I have been spying the MSDN and can't see a property/method for TextBox that
I have an EntityFramework model that has User entity that has an EntityCollection of
in writing a scripting engine, I have functions like (psuedo-code) function is_whitespace?(char c){ return
I have a pseudo random number generator (PRNG) class that I want to unit
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I'm sitting here writing a function that I'm positive has been written before, somewhere

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.