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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:10:20+00:00 2026-06-09T05:10:20+00:00

Is there a way to launch an event after html() has been fired? Such

  • 0

Is there a way to launch an event after html() has been fired? Such as:

$.post("ajax.php", {data :data}, function(data){
   $("#countries").html(data, function(){
      alert("test");
   });
});

This is not working.

EDIT: I am asking this because I want to do few things(another call) with the information coming from the call… I wanted to simplify the example…I guess programmers always want to know why…

So here it is the example updated

 $.post("ajax.php", {data :data}, function(data){
   $("#countries").html(data, function(){
        var id = $("#countries option:selected").attr("id");
        getRegions(id);
   });
});
  • 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-09T05:10:21+00:00Added an answer on June 9, 2026 at 5:10 am

    Yes you can…

    // create a reference to the old `.html()` function
    var htmlOriginal = $.fn.html;
    
    // redefine the `.html()` function to accept a callback
    $.fn.html = function(html,callback){
      // run the old `.html()` function with the first parameter
      var ret = htmlOriginal.apply(this, arguments);
      // run the callback (if it is defined)
      if(typeof callback == "function"){
        callback();
      }
      // make sure chaining is not broken
      return ret;
    }
    
    // test it all works as expected (including chaining)
    $("#mything").html("<div>My Thing</div>",function(){
      console.log("Just did my thing");
    }).css({color: 'red'})
    

    However, like everyone else says, it is unnecessary as .html() is synchronous, so you can just put your code following it rather than in a callback.

    Demo: http://jsfiddle.net/billymoon/a49P4/

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

Sidebar

Related Questions

Is there a way to launch the android browser from an app in Full
Is there a way to launch a C# application with the following features? It
Is there a way to launch a gnome-terminal from the command line (i.e., using
Is there a way I can have a custom quick launch menu on a
I'm pretty sure there must be a way to launch spotify iphone app from
I'm trying to launch another application from C# application, is there a way to
In VB.net, how can you programmatically launch a .exe file? Is there a way
Are there any event that is fired when cell is about to be selected?
Even though the API has been open since Mac OS X Leopard, there's surprisingly,
After the launch of android 4, CalendarContract class is introduce to write event in

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.