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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:42:54+00:00 2026-05-15T22:42:54+00:00

I have the following set up: <div class=click red></div> <div class=click green></div> <div class=click

  • 0

I have the following set up:

<div class="click red"></div>
<div class="click green"></div>
<div class="click blue"></div>

and when “click” is clicked I want to add the class “load” to the div. I have managed this fine, but “red” “green” and “blue” all have a background image set so I need to remove that class. Now, I know how to do this the sloppy way, I take the class for the dib “click blue” (as returned by jquery) and then strip out what I need and replace it but this is incredibly sloppy and I can’t see it being the proper method.

What’s the proper way to approach this? I need to remove the second class from the div and replace it with the class “load”. Is there some sort of method for calling each class individually, .attr(“class”)[2]?

  • 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-15T22:42:54+00:00Added an answer on May 15, 2026 at 10:42 pm

    If you know the class is “click”, you can set the class, rather then add/removing it, like this:

    $('div').attr('class', 'click load');
    

    If you know the classes (not sure if this is a simplified example) you want to remove, you can do this:

    $("div").removeClass('red green blue').addClass('load');
    

    Edit: Based on comments – You can store the class using $.data() and grab it later to restore it after the load, like this:

    In your click function:

    $.data(this, 'class', $(this).attr('class')); //store the original class
    $(this).attr('class', 'click load');          //set loading class
    

    Then to restore it later:

    $(this).attr('class', $.data(this, 'class')); //restore orignal class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: public class Person { public String FirstName { set;
I have the following class public class Car { public Name {get; set;} }
I have the following ul setup: <div id=sidebar> <ul id=themenu class=sf-menu sf-vertical> <li> <a
Say I have 4 div elements with class .navlink , which, when clicked, use
I want to be add the following to a a page: When a div
Trying to solve this problem: I have the following set of divs that when
I have a set of nested elements like such. <div id=master> <span id=num-1 class=num></span>
I have the following HTML code: <fieldset> <legend><span>Contact Details</span> <span class=edit1>Edit</span><span class=hide1>Hide</span></legend> <div> <!--content-->
I have the following html code: <div id=result1 class=result> ... some html ... ...
Following this snippet , I have set-up in my rails application to highlight the

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.