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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:59:50+00:00 2026-05-20T17:59:50+00:00

This seems to be a very common problem, although I’ve tried the recommendations to

  • 0

This seems to be a very common problem, although I’ve tried the recommendations to use addClass / removeClass rather than direct CSS manipulation, and I’ve tried mouseleave / mouseout but both cause problems.

All I want is a simple roll over that changes the class! Everything I try either inconsistently flickers the class on or off. The only other requirement I’ve been trying to accommodate is to have the listener live in a function rather than inline. Is that what’s making this impossible?

function highlight(_event){
  $(this).addClass("Highlighted");
}
function unhighlight(_event){
  $(this).delay(2000,function(){
    $(this).removeClass("Highlighted");
  });
}

$(document).ready(function () { 
  $(".Content").live('mouseenter',highlight);
  $(".Content").live('mouseout',unhighlight);
});

JSFiddle of the above

Edit

Adding .stop(true,true) seems to help quite a bit.

  • 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-20T17:59:51+00:00Added an answer on May 20, 2026 at 5:59 pm

    If you want to use live, you could do the following using .toggleClass(), .mouseover() & .mouseout():

    $(".content").live("mouseover mouseout", function() {
        $(this).toggleClass("highlight");
    });
    

    See a demo here


    Update: I couldn’t leave this one, so carried on messing with your example – after the comment you use the functions in other places. So here is what I found:

    Instead of calling .mouseout() use .mouseleave() – for some reason .mouseout() get’s called multiple times when the mouse moves round – it even gets called when the mouse first enters the object….. See the demo at the end to see what i mean here

    Secondly, the .delay() isn’t really being used correctly here – it is really meant for queuing effect’s – but what you really want is to add a delayed function (albeit it is an effect that you are after) so instead use the .setTimeout() to do the call for you.

    As per the doc’s:

    The .delay() method is best for
    delaying between queued jQuery
    effects. Because it is limited—it
    doesn’t, for example, offer a way to
    cancel the delay — .delay() is not a
    replacement for JavaScript’s native
    .setTimeout() function, which may be more
    appropriate for certain use cases.

    So the finished functions would look like this:

    function highlight(_event) {
        $(this).addClass("Highlighted");
    }
    
    function unhighlight(_event) {
        var obj = $(this);
        setTimeout(function() {
            obj.removeClass("Highlighted");
        }, 2000);
    }
    
    $(document).ready(function() {
        $(".Content").live('mouseenter', highlight);
        $(".Content").live('mouseleave', unhighlight);  
    });
    

    See the demo here this one will show you what I mean about the .mouseout() event being fired multiple times, where as the .mouseleave() function is only called once when the mouse actually leaves.
    Note: use your enter button to press the alert ok, don’t move your mouse!!

    See the demo here to see the final version working here as close to your original as possible.

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

Sidebar

Related Questions

This seems like a very simple and a very common problem. The simplest example
This seems to be a very common problem of mine: data = [1 2
Although it seems to be a very common issue, I did not harvest much
This seems very noisy to me. Five lines of overhead is just too much.
I'm relatively new to the Python world, but this seems very straight forward. Google
Now I must be missing something here, as this seems a very basic issue
Warning - I am very new to NHibernate. I know this question seems simple
This seems to be an overlooked area that could really use some insight. What
I know its a very common question, but seems like my situation is a
I have a very common use case. The user needs to enter their address

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.