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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:40:57+00:00 2026-06-04T00:40:57+00:00

My HTML is as follow. <div class=box w-25 h-25> <p>test</p> </div> <div class=box w-30

  • 0

My HTML is as follow.

<div class="box w-25 h-25">
<p>test</p>
</div>
<div class="box w-30 h-30">
<p>test</p>
</div>
<div class="box w-30 h-30">
<p>test</p>
</div>

and my css

.test {
width:100%
height:100%
z-index: 999
}

.box {
....
}

.w-25{ width: 25%; }
.w-30{ width: 30%; }
.w-40{ width: 40%; }

.h-25{ height: 25%; }
.h-30{ height: 30%; }
.h-40{ height: 40%; }

Is it possible to replace the original class with .test when I click on them individually with jQuery as to create an overlay effect?

  • 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-06-04T00:40:59+00:00Added an answer on June 4, 2026 at 12:40 am

    Remove/Replace Classes

    There are a few ways to remove all classes, and leave only one. You could use $.attr:

    $(".box").on("click", function(){
      $(this).attr("class", "test");
    });
    

    This sets the full value of class to a single classname. Alternatively, you could set the className on the element itself:

    $(".box").on("click", function(){
      this.className = "test";
    });
    

    Or, you could call $.removeClass() without any arguments (which removes all classes), and then follow that up by adding your test class:

    $(".box").on("click", function(){
      $(this).removeClass().addClass("test");
    });
    

    Avoid Ambiguity

    I’m assuming that you don’t have any other .box elements on the page – if you do, the selector used here would need to be modified just a bit to affect only the boxes we wish to target.

    If these boxes were within a larger container:

    <div id="boxes">
      <div class="box w-25 h-25">...</div>
      <div class="box w-30 h-30">...</div>
    </div>
    

    We might change our selector to include the container id:

    $("#boxes .box").on("click" function(){
      /* React */
    });
    

    Toggle On/Off

    From the comments, the OP expressed a desire to remember the original classes, and swap .test out for them if the element were clicked on a second time. Below is one possible solution to this:

    $(".box").on("click", function(){
      // Store original class attribute as data
      $(this).data("o") || $(this).data("o", $(this).attr("class"));
      // Set new class attribute to test, or to original
      $(this).attr("class", function(i,o){
        return o != $(this).data("o") ? $(this).data("o") : "test" ;
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 html box as follow: <div class=tabs> <ul class=tabNav> <li><a href=#video>Video Gallery</a></li>
I have a html file like following: <form action=/2811457/follow?gsid=3_5bce9b871484d3af90c89f37 method=post> <div> <a href=/2811457/follow?page=2&amp;gsid=3_5bce9b871484d3af90c89f37>next_page</a> &nbsp;<input
If I have a drop down list as follows <div class=editor-label> <%= Html.DropDownListFor(model =>
Ok my HTML markup is as follows: <div class=refine_search_box> <div class=heading>Refine Search</div> <div class=section_heading><a
is it possible to follow a link by it's class name instead of the
I follow the MVC model in PHP + JS + HTML + CSS Also,
Load HTML pages and check load speeds Verify completeness of HTML Follow links on
I follow example from here using section listview http://lalit3686.blogspot.com/2012/05/sectionadapter.html But how can I implement
So I was trying to follow http://developer.android.com/guide/topics/media/camera.html to create a simple app that captures
I am trying to follow Trees tutorial at: http://cslibrary.stanford.edu/110/BinaryTrees.html Here is the code I

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.