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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:04:16+00:00 2026-05-13T19:04:16+00:00

To all the jQuery guru’s out there I could use your help pointing out

  • 0

To all the jQuery guru’s out there I could use your help pointing out what is probably a silly error on my part. I’m trying to swap classes onclick when the user clicks on a div with the hotspot class. The code below swaps the class the first time I click but not the second and subsequent times. Also if there’s a cleaner way to accomplish this please let me know.

Thanks in advance for your expertise.

jQuery:

$('.hotspot').click(function() {
    if($(this).parent().attr("class") == 'checked'){
        $(this).parent().removeClass('checked').addClass('unchecked');  
    }
    if($(this).parent().attr("class") == 'unchecked'){
        $(this).parent().removeClass('unchecked').addClass('checked');  
    } 
});

Markup:

<ul id="prettyCheck">
    <li class="checked">
          <div class="hotspot"></div>
          <div class="desc"><div class="descPad">Some text</div></div>
    </li>
    <li class="unchecked">
          <div class="hotspot"></div>
          <div class="desc"><div class="descPad">Some text</div></div>
    </li>
</ul>
  • 1 1 Answer
  • 4 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-13T19:04:16+00:00Added an answer on May 13, 2026 at 7:04 pm

    try this

    $('.hotspot').toggle(function() {
          $(this).parent().removeClass('checked');
          $(this).parent().addClass('unchecked');
          // do more here...
      }, 
      function(){
          $(this).parent().removeClass('unchecked');
          $(this).parent().addClass('checked');  
          // do more here...
    });
    

    or

      $('.hotspot').click(function() {
          $(this).parent().toggleClass('checked');
          $('checkbox selector').attr('checked', $(this).parent().hasClass('checked'));
          // do more here...
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone please help with the following jQuery I need all jQuery UI buttons
I like to use JQuery for creating tabs. My issue is all jquery tab
Hello to all jQuery enthusiasts and experts!! I currently use on a project this
I noticed on my website that all jQuery functions and plugins I use start
I use the ajax-request queue as posted here: Wait until all jQuery Ajax requests
I have a select-all jquery script I got from a site (I forgot the
before this I wrote all jquery-code into main fail. Now I want to move
I want to have site wide default settings for all jQuery validation uses on
I'm not familiar at all with JQuery and I'm not very good with CSS,
I have been tinkering with javasript (jquery) all day. I want to create a

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.