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

  • Home
  • SEARCH
  • 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 8346887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:10:03+00:00 2026-06-09T07:10:03+00:00

Once I change element’s class using jQuery, the click function does not work on

  • 0

Once I change element’s class using jQuery, the click function does not work on the new class.

Here is my code

jQuery('.close').on('click', function() {
    jQuery('div').slideUp();
    jQuery(this).addClass('open');
    jQuery(this).removeClass('close');
});


jQuery('.open').on('click', function() {
    jQuery('div').slideDown();
    jQuery(this).addClass('close');
    jQuery(this).removeClass('open');
});​

You can try it here – http://jsfiddle.net/NkG9k/1/

Try clicking on the toggle button again. (it won’t slidedown the div)

  • 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-09T07:10:05+00:00Added an answer on June 9, 2026 at 7:10 am

    Try this, Apply on on document and use class filter to attach the event to your button.

    Live Demo

    jQuery(document).on('click','.close', function() {
        jQuery('div').slideUp();
        jQuery(this).addClass('open');
        jQuery(this).removeClass('close');
    });
    
    
    jQuery(document).on('click','.open', function() {
        jQuery('div').slideDown();
        jQuery(this).addClass('close');
        jQuery(this).removeClass('open');
    });​
    

    You need to delegate event on static parent of the element you want this dynamic behavior so that when the class is changed (from open to close and from close to open) of an element the event is bind automatically on this element according to newly changed class.

    Understanding Event Delegation

    Event delegation allows us to attach a single event listener, to a
    parent element, that will fire for all descendants matching a
    selector, whether those descendants exist now or are added in the
    future.

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

Sidebar

Related Questions

So here is my code: $(document).ready( function() { $('#form').bind('change', function(){ $.ajax({ type: 'get', url:
When I click on a div element of a certain class, I change contenteditable
It only works once. At second button click, nothing occurs. If I change budilnik
jQuery(document).ready(function($) { $('.c5sliderSelect').change(function() { alert('change clicked'); }); }); When I change the select list
Will the display property of an inline element change once a float property is
There is a bug in jQuery 1.4.2 that makes change event on select-element getting
I'm trying to change an element on an HTML page using CSS and then
I am having some trouble using Javascript to change the class of a div
Is it possible to change a button from disabled to enabled once the value
I need to fire a hash change event more than once per tick. My

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.