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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:20:24+00:00 2026-06-14T07:20:24+00:00

I have two classes and a function that works with one of them $(‘.div-image’).click(function(){

  • 0

I have two classes and a function that works with one of them

$('.div-image').click(function(){                    // image zoom 
    $('#image').attr("src",img_src);

    $('.div-image').attr('class','div-image-big');

});

and html something like:

<div class="div-image">
<div id="wrapper">
<img id="image" src="image.jpg">
</div>
</div>

Why after first click on the image or (div .div-image) my class div-image is changing to div-image-big. But if we click once more the function $(‘.div-image’).click(function(){…} will execute again. The question is why so? I don’t need this behavior. I want that this function work only when class is div-image not div-image-big. Thanks.

  • 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-14T07:20:25+00:00Added an answer on June 14, 2026 at 7:20 am

    The event handler is bound on the element, not the class. Which elements it is bound to is decided based on the class they have at the time that the event is bound, so changing the class later doesn’t change which elements have the event handler.

    If you want the event handler to react to the class, you should bind a delegate to the a parent element. That way the event bubbles to the parent element, and the delegate handler will check for the class at that moment. Example:

    HTML:

    <div class="image-container">
      <div class="div-image">
        <div id="wrapper">
          <img id="image" src="image.jpg">
        </div>
      </div>
    </div>
    

    Javascript:

    $('.image-container').on('click', '.div-image' ,function(){                    // image zoom 
      $('#image').attr("src",img_src);
      $('.div-image').attr('class','div-image-big');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 classes that have exact two functions. The difference between them is
I have two classes, one that inherits from the other. The base class is
I have two classes that are almost identical, besides one method. The classes have
I have a generic function in VB.Net. I also have two classes called A
i have two data classes which hold only data members(no functions). One is CallTask
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, call them A and B. They both contain a Loader
I have two MXML component files and try to work with them as classes.
I want to have a div that animates the currently active image out of

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.