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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:27:26+00:00 2026-05-31T16:27:26+00:00

I have a series of elements (lets call them ‘.my-elements’) – some load on

  • 0

I have a series of elements (lets call them ‘.my-elements’) – some load on document ready, while others are loaded later via a pagination script.

I would like to set a variable according to whether or not the mouse is over these elements. The code below works, but I suspect there is a better way… Can I do this so I only have to reference the DOM once?

$(document).on('mouseenter','.my-elements', function(){
    mouse_is_inside = true;
});

$(document).on('mouseleave','.my-elements', function(){
    mouse_is_inside = false;
});

Thanks!

  • 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-31T16:27:27+00:00Added an answer on May 31, 2026 at 4:27 pm

    You can bind to both together and check the event.type:

    $(document).on('mouseenter mouseleave', '.my-elements', function (ev) {
        mouse_is_inside = ev.type === 'mouseenter';
    });
    

    Or, if you want to keep them separate, .on has another syntax that takes an event map:

    $(document).on({
        mouseenter: function () {
            mouse_is_inside = true;
        },
    
        mouseleave: function () {
            mouse_is_inside = false;
        }
    }, '.my-elements');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of DIV elements with more DIV elements inside of them,
I have a series of nested sortable elements exhibiting some strange behaviour with z-indexes.
I have a series of elements that have a picture with a block underneath
I have a series of classes representing smart map elements: MapTextElement , MapIconElement ,
I have an XML document that contains a series of item nodes that look
Let's say I have a series of elements designed to render via float:left inside
I have a series of UITableViewCell elements with various UIControls to set model values.
So I have a series of nested ul elements as part of a tree
I have a series of HIDDEN contactID elements listed on a page and I've
I have a series of square <li> elements inside a fixed width ul .

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.