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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:53:37+00:00 2026-06-17T02:53:37+00:00

I have this super simple jQuery script that I’m having trouble getting to work.

  • 0

I have this super simple jQuery script that I’m having trouble getting to work. I’m certainly missing something as I’ve done things exactly like this before with no problem.

Codepen link: http://codepen.io/jimmykup/full/pjJhC

$("div.minimize").click(function() {

    alert("Changing to RED");
    $(this).removeClass('minimize');
    $(this).addClass('maximize');

});

$("div.maximized").click(function() {

    alert("Changing to BLUE");
    $(this).removeClass('maximize');
    $(this).addClass('minimize');

});

The problem is that once my <div>‘s class has been changed to .maximize the jQuery continues to run as if the class is still .minimize.

  • 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-17T02:53:39+00:00Added an answer on June 17, 2026 at 2:53 am

    Changing the class of an element doesn’t change which events are bound to it. You can however accomplish this using delegated events since with delegated events, the event is bound to a parent element that looks for matching child elements.

    $(document).on("click","div.minimize",function() {
    
        alert("Changing to RED");
        $(this).removeClass('minimize').addClass('maximize');
    
    });
    
    $(document).on("click","div.maximized",function() {
    
        alert("Changing to BLUE");
        $(this).removeClass('maximize').addClass('minimize');
    
    });
    

    or better yet, a single event.

    $("div.minimize,div.maximize").click(function(){
        if ($(this).is(".minimize")) {
            alert("Changing to RED");
            $(this).removeClass('minimize').addClass('maximize');
        }
        else {
            alert("Changing to BLUE");
            $(this).removeClass('maximize').addClass('minimize');
        }
    });
    

    or even better than that,

    $("div.minimize,div.maximize").click(function(){
        alert("Changing to " + $(this).is(".minimize") ? "RED" : "BLUE");
        $(this).toggleClass('maximize minimize');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be super simple but I keep getting errors. I have a JSON
Note: Now that I've typed this out, I have to apologize for the super
I'm looking at building a super simple router in javaScript...so far I have this:
I have made a super simple test case of a problem I'm having with
So let's say I have jQuery convert a simple text input from this <input
I am probably missing something very simple, but here is the situation: I have
This might be a dumb question but I can't get this super simple script
This should be a super simple thing, but I am having an issue working
Hopefully this is super simple, exists, and I'm overlooking something right under my nose.
I have a super simple python script as defined here import multiprocessing from multiprocessing

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.