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

  • Home
  • SEARCH
  • 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 3392154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:53:15+00:00 2026-05-18T03:53:15+00:00

I have some buttons that when clicked, invoke jQuery to remove and replace their

  • 0

I have some buttons that when clicked, invoke jQuery to remove and replace their class. The jQuery.mouseover event that I want to call is ignoring the manipulated classes, and only obeying the classes from the page load.

Here’s an example JSFiddle

Details below:

I have a row of buttons that, when rolled over invoke some jQuery to add a .highlighted class to objects elsewhere on the page:

Here’s example HTML:

<ul id="portfolioLinks">
    <li class="activeButton kittens"><a class="kittens" href="#"></a></li>
    <li class="activeButton otters"><a class="otters" href="#"></a></li>
    <li class="depressed donkey"><a class="donkey" href="#"></a></li>
</ul>

and the corresponding jQuery code:

var selectedType = '.' + $(this).attr('class');


$("li.activeButton a").mouseenter(function() {

    var selectedType = '.' + $(this).attr('class');

    $("div.pageContent div" + selectedType).addClass('highlighted');

});     

$("#portfolioLinks a").mouseleave(function() {

    $("div.pageContent div").removeClass('highlighted');

});

This works fine on the static content from the page load, but when I click on a button I get
jQuery to add a .depressed class to $(this) and give all the others .activeButton:

$("#portfolioLinks a").click(function() {


    $("#portfolioLinks li").addClass('activeButton').removeClass('depressed');

    $(this).parent().removeClass('activeButton').addClass('depressed');

//do some other stuff

}); 

However, it seems to completely ignore the altered classes, and continues highlighting the divs matching a button that lacks the .activeButton class.

I spent most of last night and this morning trying to figure this out. I’ve tried all manner of .nots, :nots and ifs, and I’m now completely lost.

Any guidance would be extremely appreciated.

  • 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-18T03:53:15+00:00Added an answer on May 18, 2026 at 3:53 am

    Use .delegate() here instead, like this:

    $("#portfolioLinks").delegate("li.activeButton a", {
       mouseenter: function() {
        var selectedType = '.' + $(this).attr('class');
        $("div.pageContent div" + selectedType).addClass('highlighted');
      },
      mouseleave: function() {
        $("div.pageContent div").removeClass('highlighted');
      });
    

    Here’s your fiddle updated with the above code, working.

    The issue is that when you do $("li.activeButton a") you’re not binding anything to the class, you’re binding events to the elements you found with the class when it was run…the elements now have event handlers bound. Any changes in the future are irrelevant, the handlers are bound.

    With .live() and .delegate() however, the selector is checked when the event happens, so it does matter that the class changed. As a bonus, it’s also cheaper for many elements, since there’s one set of handlers on #portfolioLinks.


    If using jQuery older than 1.4.3, you’ll need the non-map form, like this:

    $("#portfolioLinks").delegate("li.activeButton a", "mouseenter", function() {
        var selectedType = '.' + $(this).attr('class');
        $("div.pageContent div" + selectedType).addClass('highlighted');
    }).delegate("li.activeButton a", "mouseleave", function() {
        $("div.pageContent div").removeClass('highlighted');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with some radio buttons that are disabled by default. When
I have a subclass s of UIView. I want to put some buttons and
I'd like to have a TabNavigator component that has a close button for some
I have created an item swapper control consisting in two listboxes and some buttons
I have a page with some dynamically added buttons. If you click a button
I have three buttons and need to save some data. I have a idea,
I've some CSS problem in Firefox 3. I have several image buttons on my
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
Currently, I have some basic code to play a simple tone whenever a button
I have to display yes/no button on some condition on my asp.net page ,

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.