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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:12:18+00:00 2026-06-13T11:12:18+00:00

How to trigger jQuery-UI effect only once on mouseenter? http://jsfiddle.net/MG4JZ/ $(‘#menu a’).hover( function() {

  • 0

How to trigger jQuery-UI effect only once on mouseenter?

http://jsfiddle.net/MG4JZ/

$('#menu a').hover(
  function() {
    $(this).css({
        'background-color': 'white',
        'color': 'black',
    }).effect('slide'); // EFFECT
  }, function() {
    $(this).css({
        'background': 'none',
        'color': 'white',
    });
});

It keeps running forever while mouse is over.

  • 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-06-13T11:12:19+00:00Added an answer on June 13, 2026 at 11:12 am

    The problem is the slide effect being used because the <a> slides in from the left and gets a second .hover() event. I use the fact that the element gains position:relative from jQueryUI when it is animating to determine whether to add the effect or not.

    Demo

    Adding the CSS

    #menu a:hover {
        background-color:white;
        color:black;
    }​
    

    and simply using .mouseenter()

    $('#menu a').mouseenter(function() {
        var $this = $(this);
        if ($this.css('position') === 'relative') return;
        $(this).effect('slide'); // EFFECT
    });​
    

    seems to solve it for me.

    Edit: So thanks to Matthew in the comments for pointing out that when hovering on the far right, the event still fires multiple times. So here is an updated answer. It uses the newer jQuery .on() syntax but you could still use the older methods to achieve the same result. It now uses two events, one on the anchors to add the hover style and effect but only if when entering the anchor, the element does not already have the class. I also remove the hover class from all other anchors when hovering an anchor. The second event covers the removal of the hover class when exiting the whole menu. Without this second event the last anchor hovered when moving away from the menu is left with the .hover class.

    Updated demo

    JavaScript

    var $anchors = $('#menu a');
    
    $('#menu').on('mouseenter', 'a', function() {
        $anchors.not(this).removeClass('hover');
    
        var $this = $(this);
        if ($this.hasClass('hover')) return;
        $this.addClass('hover').effect('slide'); // EFFECT
    });
    
    $('#menu').on('mouseleave', function() {
        $anchors.removeClass('hover');
    });​
    

    CSS

    #menu {
        background-color: black;
    }
    
    #menu a {
        display: block;
        color: white;
    }
    
    #menu a.hover {
        background-color:white;
        color:black;
    }​
    

    HTML

    <div id="menu">
        <a href="#">Link 1</a>
        <a href="#">Link 2</a>
        <a href="#">Link 3</a>
    </div>
    

    Hope this helps.

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

Sidebar

Related Questions

EDIT My jsfiddle entry is here : http://jsfiddle.net/ehNrE/3/ All the codes(only those required) below
I'm using jQuery to develop in web environment. I want to know why $(#a#trigger).trigger('mouseenter');
I have a problem with Jquery function getJSON, the action url does not trigger
I've done some easy .hover(function() statement in jQuery. When i hover over a text
I have a number input that should trigger jQuery on every change. To do
Here I am doing a basic trigger example but jquery is unable to execute
I'd like to be able to use jQuery to trigger an event if the
I am using jquery ui datepicker icon trigger. I want to give the icon
Is it possible to trigger copy event from JavaScript/jQuery? I want to simulate copy
In jQuery, is it possible to invoke a callback or trigger an event after

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.