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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:33:05+00:00 2026-06-12T07:33:05+00:00

I was under the impression that jQuery’s on event handler was meant to be

  • 0

I was under the impression that jQuery’s on event handler was meant to be able to ‘listen’ for dynamically created elements AND that it was supposed to replace the behavior of live. However, what I have experienced is that using on is not capturing the click event whereas using live is succeeding!

The tricky aspect of my situation is that I am not only dynamically creating content but I’m doing it via an AJAX .get() call, and inserting the resultant HTML into a modal .dialog() jQueryUI popup.

Here is a simplified version of what I was trying to accomplish (wrapped in $(document).ready(...) ):

$.get("getUserDataAjax.php", queryString, function(formToDisplay) {
    $("#dialog").dialog({
        autoOpen: true,
        modal: true,
        buttons...
    }).html(formToDisplay);
});
$(".classThatExistsInFormToDisplay").on("click", function() {
    alert("This doesn't get called");
});

From the documentation for on I found this which which was how I was approaching writing my on event:

$("p").on("click", function(){
    alert( $(this).text() );
});

However, for some reason, live will work as I expect — whereas on is failing me.

This isn’t a question for “how can I make it work” because I have found that on will succeed (capture clicks) if I declare it inside the function(formToDisplay) callback.

My question is: what is wrong with on that it isn’t finding my dynamically created elements within a modal popup? My jQuery instance is jquery-1.7.2. jQueryUI is 1.8.21.

Here are two jsFiddles that approximate the issue. Click the word “Test” in both instances to see the different behavior. The only difference in code is replacing on for live.

Where the click is captured by live.

Where the click is NOT captured by on (click ‘Test – click me’ to see nothing happen).

I realize I may just be using on inappropriately or asking it to do something that was not intended but I want to know why it is not working (but if you have something terribly clever, feel free to share). Thanks for your wisdom!

Update / Answer / Solution:

According to user ‘undefined’, the difference is that on is not delegated all the way from the top of the document object whereas live does/is.

As Claudio mentions, there are portions of the on documentation that reference dynamically created elements and that what you include in the $("") part of the query needs to exist at runtime.

Here is my new solution: Capture click events on my modal dialog, which, although it does not have any content when the event is created at runtime, will be able to find my content and element with special class that gets generated later.

$("#dialog").on("click", ".classThatExistsInFormToDisplay", function() {
    ... //(success! Event captured)
});

Thanks so much!

  • 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-12T07:33:07+00:00Added an answer on June 12, 2026 at 7:33 am

    live delegates the event from document object, but on doesn’t, if you want to delegate the event using on method, you should delegate the event from one of static parents of the element or document object:

    $(document).on("click", ".clickHandle", function() {
        alert("Content clicked");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was under the impression that jQuery is JavaScript Framework, but when am searching
I was under impression that in F# the following two lines are supposed to
I was under the impression that since I'm using the current version of jQuery,
I was under impression that .replace and -replace were the exact same thing, however
I was under the impression that Page Methods and Script Methods created tiny AJAX
I was under the impression that when we send mail to any domain (i.e.
I'm under the impression that a control in a nested UpdatePanel will cause the
I was under the impression that when you called Flush() in a StreamWriter object
I was under the impression that I could get the value of a select
I was under an impression that the left hand side of the colon :

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.