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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:25+00:00 2026-06-17T14:20:25+00:00

Since .live() is deprecated, I started to use .on(). I have the following code:

  • 0

Since .live() is deprecated, I started to use .on().

I have the following code:

$('.myClass').on("click", function(event)
{
    var args = '......';

     SendAjax(args);
});

The SendAjax function does this:

SendAjax(args)
{
    $.ajax(
    {
        type: "POST",
        url: webPageName,
        data: queryParams+'&'+unique,
        success: function(result)
        {
            MyReturnFunction(result);
        }
    });
}

The ajax will return to this function:

MyReturnFunction(response)
{
      $('.myClass').html(response);
}

But after this MyReturnFunction(), the events on .myClass doesn’t work anymore. How do I fix this with .on() or .bind()?

  • 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-17T14:20:26+00:00Added an answer on June 17, 2026 at 2:20 pm

    The .on() function can take an extra argument:

    $('body').on('click', '.myClass', function() { ... });
    

    That’s what .live() did for you, but it was a backwards API design. Now you have to decide where to put the delegated handler. The body element is a good default, but it can be any parent. Sometimes when you’re handling clicks on things in tables it’s nice to do the binding at the <table> element (though the body works fine then too).

    So basically the rule is that when you used to write:

    $('something').live('event-name', function() { ... })
    

    you write:

    $('container-selector').on('event-name', 'something', function() { ... })
    

    The “container-selector” says where you want the real event handler placed — the one that checks to see whether the target of a bubbled event matches the given “something” selector. As before, you can pass a list of event names (separated by spaces) instead of just one. There’s also a variant that lets you pass an object mapping event names to functions.

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

Sidebar

Related Questions

Since the live() method is deprecated as of version 1.7, I started going through
Since $(table).delegate(td, hover, function(){ $(this).toggleClass(hover); }); Is equivalent to the following code written using
$(div#foobar).live('click', function() { }); $(window).hashchange(function() { }); How can I stop firing hashchange event
Since version 1.7 live is deprecated. Following example is easy to make compatible with
So I have a code that looks something like this $(.something).live({ mouseover:function(e){ //do stuff
$('.quote').live('click', function() { var quote = test; $(#msg).append(quote).scrollTop($('#msg')[0].scrollHeight).focus(); }); This function just copies test
I'm loading some content via ajax and need to use the live() function. Since
Since now I have only used plugin for editing and the way I use
I was just reading http://api.jquery.com/event.stopPropagation/ Since the .live() method handles events once they have
Here is a simple piece of code: HTML: <div id=close>Click me</div> JS Code: $(#close).click(function(){

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.