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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:44:39+00:00 2026-06-08T20:44:39+00:00

I have this problem, but in short: I have a self calling function (function

  • 0

I have this problem, but in short: I have a self calling function (function TCC() {...})(); that generates two sections of elements, among other things. These elements are generated with the class btn. Another JQuery function of $('.btn').click(function () {...}; [with an appropriate console.log() ] is showing that all elements on the page with class btn are being clicked except the two aforementioned sections’ elements.

One comment suggests “The issue occurs because you bind the click event, before the “column button generator” loop.”, and a suggested solution of:

$.each(cols, function(i) {...}).done(function(){ //Add click event handler now });

First question is can someone elaborate on ‘because you bind the click event, before the “column button generator” loop.’

Second question is about the proposed solution. Since I have two separate lines of code for generation, and the $('btn').on('click', function() {...}); block is over 50 lines, how do implement a solution without duplicating the lines of code, as I would assume the .done() method would require this. The page in question is here.

  • The current scope structure of the generation code relative to the .on('click') is as follows (sorry for pic, but StackOverflow didn’t like the formatting for some reason):

    enter image description here

Does the scope of the generation lines of code effect this, and if so, can I pull them out of the self calling function to fix the ‘bind to click event’ the suggestion spoke of?

I appreciate your help and expertise, as learning programming from scratch, these types of structure lessons are often left out of the online learning tools often included in textbooks.

  • 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-08T20:44:40+00:00Added an answer on June 8, 2026 at 8:44 pm

    You really should’ve posted the actual code. But no matter. I think the only issue why your click events are not being called, is that you’ve used an incorrect syntax.

    The on function of jQuery, has the following syntax –

    HTML

    <div class='button_container'>
        <button> This is a button</button>
        <button> This is a button</button>
    </div>
    

    JavaScript

    $('.button_container').on('click', 'button', function(){
        console.log('I have been clicked!');
    });
    //Note the the second selector 'button' within the declaration
    

    Since the on function basically replaces the live and delegate functions, the handler is now defined for all buttons in div.buttons, irrespective of when and how it was created (meaning dynamically created). This can be bit misleading.

    If you do a simple select of the sort

    $('button').on('click', function(){ /* do something **/ })
    

    jQuery assumes that you are talking about direct event binding – i.e, the dom element is already loaded. It won’t affect any dynamically created elements (mind you, if you attach the bindings after the creation code, it will still work on those elements, as they are already present in the DOM).

    Unless you provide the second selector, this the default behavior. This is a bit confusing, but moving on. If you want to target those elements before actually creating them, do something of this sort

    //Right syntax
    $(document).on('click','button', function(){ /* do something **/ })
    //This will bind to all buttons
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this quite popular problem, but have failed to find a solution that
I have tried searching over the internet about this problem but not able to
NOTE: I have solved the majority of this problem but have run into a
I have looked at many different peoples answers to this problem but they only
I have read a lot of related topics here regarding this problem but I
I tried many ways to solve this problem but none works. suppose I have
I've searched google and SO for a solution to this problem but have not
I have read the other threads regarding this same problem but I still don't
hey guys having this really simple problem but cant seem to figure out have
I am in ASP.NET, but the problem is completely HTML related. I have this

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.