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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:46:48+00:00 2026-05-15T19:46:48+00:00

I have a Javascript module the following Javascript: EntryController = function$entry(args) { MainView(); $(‘#target’).click(function()

  • 0

I have a Javascript module the following Javascript:

EntryController = function$entry(args) {

    MainView();

    $('#target').click(function() {
      alert('Handler called!');
    });

}

MainView() has a callback that creates the #target button. Because of the callback the code will pick up and run through the rest of the code $(‘#target’) … before #target is created. If this is the case the event is never hooked up to the #target. If I put a breakpoint at $(‘#target’) that’ll give the callback enough time to return and build the #target, when I press play everything works as expected.

What’s the best way to deal with this? I would like all events to take place in the controller so it can choose which view to send it to.

I was thinking about placing the entire $(‘#target’).click … inside MainView() and instead of alert(‘Handler called!’); I’d put a references to EntryController.TargetEventRaise(), but that started to look a bit like steady code. What’s the best way to approach this?

  • 1 1 Answer
  • 1 View
  • 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-05-15T19:46:48+00:00Added an answer on May 15, 2026 at 7:46 pm

    You’re looking for jQuery’s live event handlers, which will handle an event on every element that matches the selector, no matter when the element was created.

    For example:

    $('#target').live('click', function() {
        alert('Handler called!');
    });
    

    Alternatively, you could make the MainView function itself take a callback, and add the handler in the callback. You could then call the callback in MainView inside of its callback.

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

Sidebar

Related Questions

I have Javascript that opens another window and registers a click handler for all
In a custom module, I have the following (to add javascript to a particular
I'm using the javascript module pattern, and have this so far: var APP; if(APP
I have Javascript function defined in the main index.html file. One part of this
I have JavaScript form validation functions like so: function validate_name(field) { if (field ==
I have defined a GWT module that includes an external javascript file using tag.
I have the following DOM structure: <div id=module-main> <div id=module-crumbs> <h4>Hello</h4> </div> </div> When
I have recently Created a sliding module for Joomla, and I have a JavaScript
I have the following code snippet to enable extension after firefox quit, observe: function
I have JavaScript application, where I use client-side templates (underscore.js, Backbone.js). Data for initial

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.