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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:39:35+00:00 2026-06-03T07:39:35+00:00

I can’t understand this. When I want to remove class B from a div

  • 0

I can’t understand this.

When I want to remove class B from a div and add class D into it,

It works.

But class D‘s function can’t be triggered.

$('.B').click(function() { 
        $('.A').animate({
           "left": "+=10%"
        },{
           duration:1000,
           complete: function(){
              $("#C").addClass("D").removeClass("B");
              } 
           }); 
});  



 $(".D").click(function() { 
        $(".A").animate({
            "top":"+=40%"
        },{
            duration:2000,
            complete:function(){
                 $("#C").addClass("B").removeClass("D");
             }
          });
}); ​

I’ve tried putting class D‘s function into class B‘s function like this:

$('.B').click(function() { 
        $('.A').animate({
           "left": "+=10%"
        },{
           duration:1000,
           complete: function(){
              $("#C").addClass("D").removeClass("B");
              $(".D").click(function() { 
                   $(".A").animate({
                       "top":"+=40%"
                   },{
                       duration:2000,
                       complete:function(){
                           $("#C").addClass("B").removeClass("D");
                       }
                   });
               }); ​
              } 
           }); 
});  

and both functions work for the first time and after that they behavior in a bizarre way.

I would appreciate if someone can explain to me why and provide me with a solution.

  • 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-03T07:39:36+00:00Added an answer on June 3, 2026 at 7:39 am

    When you use $.click, you bind only to the elements that match the select at that time. If you want to match all future elements as well, use $.on instead:

    $("body").on("click", ".D", function(){
      /* Class D Stuff */
    });
    

    This will react whether the clicked element had class="D" to begin with, or if it acquired it later on through something like $(this).addClass("D").

    The "body" part ideally should be a container much closer to your clicked elements. For instance, if you had the following:

    <body>
      <div id="container">
        <a href="#" class="B">Foo</a>
        <a href="#" class="D">Bar</a>
      </div>
    </body>
    

    You should use #container instead of body in the jQuery function.

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

Sidebar

Related Questions

can someone show me the regex for this preg_match. I want to make sure
Does anyone know how can I replace this 2 symbol below from the string
Can anyone explain how this both can compile and how it works? List<? super
Can 2 or more equations defining a function in Haskell share the same where
can I make my own headers in HTTP request ? e.g. This is normal
Can this be done? It seems like this should be possible. In general, I
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
Can I figure out if a function has already been assigned to an event?
I want to count how many characters a certain string has in PHP, but
Can I run this in a Windows command prompt like I can run it

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.