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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:43:38+00:00 2026-05-25T02:43:38+00:00

I have following jQuery example: $(‘li.mega’).mouseover(function() { var megaTrue = 1; }); $(‘li.mega’).mouseout(function() {

  • 0

I have following jQuery example:

$('li.mega').mouseover(function() {
    var megaTrue = 1;
});

$('li.mega').mouseout(function() {
    var megaTrue = 0;
});

and than

function functionName() {

        if( megaTrue == 1 ) {

             //do something

        } else {

            //do nothing
            return false;   

        }               
    }

But megaTrue will be undefined, is there something like a GLOBAL variable in jQuery?

All suggestion much appreciated.

  • 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-25T02:43:39+00:00Added an answer on May 25, 2026 at 2:43 am

    You can, but it’s very rarely a good idea to use globals: this is true in Javascript as much as anywhere. The semantic, meaningful place to store data is with the element itself. jQuery supports this with the data method:

    $('li.mega').mouseover(function() {
        $(this).data('mousedOver', true);
    }).mouseout(function() {
        $(this).data('mousedOver', false);
    });
    

    If you have many li.mega elements and you don’t care which one is moused over, you could set the value on the parent element:

    $('li.mega').mouseover(function() {
        $(this).parent().data('mousedOver', true);
    }).mouseout(function() {
        $(this).parent().data('mousedOver', false);
    });
    

    Sorry, missed a crucial step: checking the value. You can then get the value off the element using the data method like this:

    if ($('li.mega').data('mousedOver')) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
For example I have following jQuery code: var div1 = $(divs).next(); How do I
I have the following jQuery function (simplified): function doSomething(el, str) { el.find('.class').text(str)); } Don't
I have the following function: jQuery(document).ready(function($){ $(div.findButton).click(function(){ UidID=Math.floor(Math.random()*1000); PostCode=$(#postcode).val(); $.get(result.php, {postcode: PostCode,uid:UidID}, function(response){ $(#result).html(response);
Suppose I have the following (shortened for simplicity): jQuery(#grid).jqGrid({ ... ondblClickRow: function() { //
I'm working with a tabbed interface and have the following jQuery function set up
I have the following Javascript/jQuery function: function addEventHandler(){ $(div).mouseenter(function() { $(this).html(Over); }).mouseleave(function() { $(this).html(Out);
I have the following function that opens jQuery UI's dialog warning about the delete
Assume I have the following example: Example One $('.my_Selector_Selected_More_Than_One_Element').each(function() { $(this).stuff(); $(this).moreStuff(); $(this).otherStuff(); $(this).herStuff();
Lets say I have the following jQuery plugin (this is just an example to

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.