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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:12:48+00:00 2026-06-12T19:12:48+00:00

Im trying to make the divs change class from normal to thin ONLY if

  • 0

Im trying to make the divs change class from “normal” to “thin” ONLY if they have the class “normal”. But somehow they just change back and forth, the IF statement seems to be written completely wrong 🙂

Here is the code

<div class="normal">1</div>
<div class="normal">2</div>
<div class="normal">3</div>
<div class="normal">4</div>
<div class="normal">5</div>
<div class="normal">6</div>

CSS:

.normal{
float:left;
height:200px;
width:100px;
border:1px dotted gray;
}

.thin{
float:left;
width:50px;
height:200px;
border:1px dotted gray;
background-color:#5a5a5a;
}

jQuery

$(document.body).click(function () {
  $("div").each(function () {
    if ($(this).hasClass("normal")) {
      $(this).toggleClass("thin", 300);         //Problem here?
    } else {
      this.style.color = "red";
    }
  });
});
  • 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-12T19:12:50+00:00Added an answer on June 12, 2026 at 7:12 pm

    @Egis as per your requirement the code should like below :

    $(document.body).toggle(
        function () {
            $("div.normal").animate({
                width: "50px",
            }, "slow", function(){ $(this).addClass("thin"); });
        },
        function(){
            $("div.normal").animate({
                width: "100px",
            }, "slow", function(){ $(this).removeClass("thin"); });
        }
    );
    

    DEMO

    I hope this is what you are looking for, Good Luck !!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to dynamically make divs that are clickable. I have inserted a
I'm trying to have a few divs control the change and to hide or
So, I am trying to make floated divs to hide in parent's div, but
I am trying to make a piechart by rotating the overlapping divs. I need
Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
Had a idea and now trying to make it happen. Idea: Have a HTML
I'm trying to make a web page that only has content within the page
I have this test page: http://www.problemio.com/problems/problem.php?problem_id=305 I am trying to make the form towards
I am trying to make 3 floating divs - left, center and right with
I'm trying to make a couple of DIVs clickable in its entirety. I tried

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.