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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:36:11+00:00 2026-05-14T09:36:11+00:00

I am a bit confused with this: I have a page with a set

  • 0

I am a bit confused with this:

I have a page with a set of buttons (i.e. elements with class attribute ‘button’. The buttons belong to one of two classes (grp1 and grp2).

These are my requirements

  • For buttons with class attribute ‘enabled’, when the mouse hovers over them, a ‘button-hover’ class is added to them (i.e. the element the mouse is hovering over). Otherwise, the hover event is ignored

  • When one of the buttons with class attribute ‘grp2’ is clicked on (note: it has to be ‘enabled’ first), I disable all ‘buttons’ in that group (i.e. remove the ‘enabled’ class for all elements with class ‘grp2’ (should probably selecting for elements with class ‘button grp2’ AND ‘enabled’ – but I am having enough problems as it is, so I need to keep things simple for now).

This is what my page looks like:

<html>
<head>
   <title>Demo</title>
   <style type="text/css">
     .button {border: 1px solid gray; color: gray}
     .enabled {border: 1px solid red; color: red}
     .button-hover {background-color: blue; }
   </style>
   <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
   <div class="btn-cntnr">
      <span class="grp1 button enabled">button 1</span>
      <span class="grp2 button enabled">button 2</span>
      <span class="grp2 button enabled">button 3</span>
      <span class="grp2 button enabled">button 4</span>
   </div>
   <script type="text/javascript">
      /* <![CDATA[ */
      $(document).ready(function(){

        $(".button.enabled").hover(function(){
            $(this).toggleClass('button-hover');
          }, function() {
            $(this).toggleClass('button-hover');
        });

        $('.grp2.enabled').click(function(){ $(".grp2").removeClass('enabled');});
       });      
      /* ]]> */
   </script>
</body>
</html>

Currently, when a button with class ‘grp2’ is clicked on, the other elements with class ‘grp2’ have the ‘enabled’ class removed (works correctly).

HOWEVER, I notice that even though the class no longer have a ‘enabled’ class, SOMEHOW, the hover behavior is still applied to these elements (WRONG). Once an element has been ‘disabled’, I no longer want it to respond to the hover() event.

How may I implement this behavior, and what is wrong with the code above (i.e. why is it not working? (I am still learning jQuery)

  • 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-14T09:36:12+00:00Added an answer on May 14, 2026 at 9:36 am

    You could attach hover listener to all buttons, and then check at runtime, whether the particular button has class enabled.

    $(".button").hover(function(){
        if ($(this).hasClass('enabled')) {
          $(this).addClass('button-hover');
        }
      }, function() {
        $(this).removeClass('button-hover');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit confused why this code compiles. I leave out the necessary
Bit of an obscure one this. My setup is all running on my local
I have this class model where, Bank is a class which is now going
I am a bit confused on this, I made a report template in Birt
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused here. Microsoft as far as I can tell claims that
I'm a bit confused that the argument to crypto functions is a string. Should
I'm a bit confused from what I've heard Java doesn't do events. But I
I'm fairly new to the Zend Framework and MVC and I'm a bit confused

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.