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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:27+00:00 2026-05-31T18:46:27+00:00

I am curious why when I replace .live() with .on() my events don’t work

  • 0

I am curious why when I replace .live() with .on() my events don’t work after inserting AJAX’s response via html() method. Assume I have html structure:

<div class="a">
   <a href="" class="alert-link">alert</a>
   <a href="" class="ajax-update">update</a>
</div>

and jQuery code something like:

$('.alert-link').on("click", function(){
 alert('abc');
 return false;
});

and ajax-update will trigger request, which response will be:

alert
update

and I will insert it into parent(). Then pressing again alert-link will result in redirecting to / but if I change .on() to .live() then again alert will be shown. What am I missing here? I have read that .on() is replacement both for .delegate() and .live().

  • 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-05-31T18:46:28+00:00Added an answer on May 31, 2026 at 6:46 pm

    .on combines and replaces .bind, .live, and .delegate. The syntax $('selector').on('event', callback) is the moral equivalent of bind, not live.

    Add a filtering selector to your call to on:

    $('container').on('click', 'child-filter', callback);
    

    In this case,

    $('.a').on("click", ".alert-link", function(){
        alert('abc');
        return false;
    });
    

    This was changed because it is more efficient to attach a delegate handler to a more localized container element than the old .live style of attaching the handler to the root of the DOM.

    In other words, even though alert-link elements will only appear inside of a small a div, with .live, jQuery listens to every single click event on the page and compares it to the delegated selector. By being more targeted, jQuery only has to process clicks on elements within a.

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

Sidebar

Related Questions

I'm curious why is method fillInStackTrace of java.lang.Throwable public? This method replaces original stack
Curious to know how people set up their personal and/or work development environment, in
I am very curious to know if it is possible to replace the normal
In Visual Studio, I'm very curious to know the regular expression to replace: MyLog.LogFatal(Error
I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with
I'm curious what the most performant method of doing string transformations is. Given a
I am curious on how to replace all the instances of '(A)' in a
Just curious. what are the differences between? var a=text.replace(/(Nullam|ligula|in)/ig,'`<b>$1</b>`'); with var string = Nullam|lingula|in;
I am curious about what is the best way to do this: assume I
I've been getting an 'Invalid JSON' after making a jQuery AJAX Request. This request

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.