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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:21:50+00:00 2026-05-26T02:21:50+00:00

I have a jquery script where if user mouseenter, element is .show(), and mouseleave,

  • 0

I have a jquery script where if user mouseenter, element is .show(), and mouseleave, element is .hide(). But what if you have the user click, and want to show the element even if the mouse leaves? How would you override the mouseleave, when user clicks?

My script goes something like this

    $('.block').live("mouseenter",function(){
                var id= $(this).attr('id');
                $('#'+id).show();
                $(this).click(function(){
                      //show? is this how it works? not sure where click should go.
        });

            }).live("mouseleave",function(){
            var id= $(this).attr('id');
            $('#'+id).hide();

        });

How do I deal with click?

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-26T02:21:51+00:00Added an answer on May 26, 2026 at 2:21 am

    You can unbind the mouseleave event handler when the user clicks the div

    $(function() {
    
        $('.block').live("mouseenter", function() {
            var id = $(this).attr('id');
            $('#' + id).show();
            $(this).click(function() {
                //show? is this how it works? not sure where click should go.
            });
    
        }).live("mouseleave", function() {
            var id = $(this).attr('id');
            $('#' + id).hide();
    
        }).live("click",function(){
             $(this).unbind("mouseleave"); 
             $(this).removeClass('block');  //this was added
        });
    });
    

    Try could even try using using $('.block').hover(function(){},function(){}) instead of handling the mouseover and mouseleave events individually.Also if possible use delegation instead of using live. But that is just an opinion not related to your question.

    Edit : with delegate . Note for this to work the div.blocks need to be as

    <div id="container">
    <div class="block">
    <div class="block">
    </div>
    
    
    
    $('#container').delegate('.block', 'mouseenter', function() {
        var id = $(this).attr('id');
        $('.msg').html('I entered :' + id);
    
    });
    $('#container').delegate('.block', 'mouseleave', function() {
        var id = $(this).attr('id');
        $('.msg').html('I came out of :' + id);
    
    });
    $('#container').delegate('.block', 'click', function() {
        var id = $(this).attr('id');
        $('.msg').html('I entered and clicked :' + id);
        $(this).unbind("mouseleave");
        $(this).removeClass('block');
    }); 
    

    Also you would need to remove the class block from the div which is clicked so as to counter the effect of .live or .delegate

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

Sidebar

Related Questions

I have this jquery script which suppose to hide/show div element base on the
If I want to mouseenter a div, an element will show, then when mouseleave,
I have a jquery script, where if you mouseenter and element, something shows, and
I have a very simple jQuery script.. all I want it to do is
I have a datalist being generated with ASP, but unfortunately the jQuery script that
I have a jQuery vote script that allows a user to vote on a
I have a jQuery search script based on the Bing API. When a user
I have a jQuery search script that uses tabs for the user to define
I have a jquery script that attaches a click event to every link, running
I have a jQuery search script that uses tabs for the user to define

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.