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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:23:46+00:00 2026-05-15T01:23:46+00:00

I have 2 anchor links (a.selector) and when one is clicked it has a

  • 0

I have 2 anchor links (a.selector) and when one is clicked it has a class applied to it of ‘active-arrow’ and the click also removes the class of the same name from the other anchor as well as lowering the opacity to 0.2.

I then want to have a fade effect when the user hovers over the anchor that doesn’t have ‘active-arrow’ applied to it so that it goes to full opacity when mouseenters and back to 0.2 when mouseleaves.

The problem im having is that both .not and :not don’t seem to be working as expected, the hover effect works but if I click on the anchor whilst hovering the ‘active-arrow’ class is applied but when mouseleaves the opacity is faded down to 0.2 again even though the ‘active-arrow’ class is applied. Also the hover then doesn’t work for the other a link which has had ‘active-arrow’ removed.

Bit of a hard one to explain so heres some code that hopefully helps a bit.

*//If a.selector doesn't have the class 'active-arrow' then run the hoverFade function*
$("a.selector").not(".active-arrow").hoverFade();

//Functions for first element
        $('a.selector-1').click(function () {
            $('a.selector-2').removeClass('active-arrow'); //Remove background image from corresponding element
            $('ul#storage-items-2').fadeOut(1200).addClass('hide'); //Fade out then hide corresponding list
            $(this).addClass('active-arrow', 'fast'); //Add background image to current element
            $('ul#storage-items-1').removeClass('hide').fadeIn(1800); //Unhide and fade in the list
            $('a.selector-2').fadeTo(500, 0.2); //Fade corresponding element
            $(this).fadeTo(800, 1);//Fade this element to full opacity
        });

I only included the code for teh first anchor (a.selector-1) as the code for the second anchor is identical but just changes the class names to a.selector-2.

Also the hoverFade function is in a seperate file so we can re-use it.

    jQuery.fn.hoverFade = function() {
return this.each(function(){
        $(this).hover(
                function () {
                    $(this).fadeTo(500, 0.8);
            }, 
                function () {
                    $(this).fadeTo(500, 0.2);
        });
  });

}

Each anchor link fades in and fades out a UL as well.

Any help is most appreciated

Thanks

Giles

  • 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-15T01:23:47+00:00Added an answer on May 15, 2026 at 1:23 am

    This is a case where you want to use .live() or .delegate(), like this:

    $("a.selector:not(.active-arrow)").live('mouseenter', function () {
      $(this).fadeTo(500, 0.8);
    }).live('mouseleave', function () {
      $(this).fadeTo(500, 0.2);
    });
    

    If you use .delegate() the top line would look like this (ID = ID of shared parent to all these links):

    $("#ID").delegate("a.selector:not(.active-arrow)", 'mouseenter', function () {
    

    The reason what you currently have doesn’t work is that it binds the event handler to the elements, the elements only had to match the selector you used when you found them for binding, once that happens, the .hover() mouseenter and mouseleave event handlers are bound on that element. The fact that the class changes later doesn’t really matter, the handlers are there to stay.

    Using the approach above, the events aren’t actually on the elements directly, they sit on a parent, document in the case of .live() or #ID in the case of .delegate(). When the mouse events happen on an element they bubble up, and the parent sees them, checks if the selector that handler is for matches right then, and if so executes. This makes the class changing actually matter, as it’s checked when the event happens, rather than when it was bound.

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

Sidebar

Related Questions

I have any number of anchor links on a page that need to execute
I have several such anchor links as shown below. <a href=http://google.com onClick=unhook()> Google </a>
I have two elements (a button and an anchor tag) both with a dynamical
I have implemented a tiny msc in my project . I want one text
I want my links not to have the weird outline and the best way
I have added a custom file selector plugin for FCKeditor and inserting of a
I have in my site some links that are just used to display informative
I have a script that appends some rows to a table. One of the
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.