Graham Charles Graham Charles - 1 year ago 66
jQuery Question

does jquery.html() have a "ready" or "complete" callback?

I'm using DOM insertion to generate some data entry dialogs. I'm finding that in some browsers, particularly mobile browsers and IE-Mac, manipulations immediately after the

call don't fire, presumably because the modified DOM is not yet ready. For example:

type: "GET",
url: url,
dataType: 'html',
success: function (data, textStatus, jqXHR) {

// hide address
$("#theDialog #BillingAddress").closest("li").hide();

This works most of the time, but certain browsers sometimes fail to hide the indicated
. And it's been challenging to debug, because going to console seems to allow the browser to complete the DOM insertion, and so the
always works when stepping through the code.

I suppose what I'm after is either a
or a callback from the
method. But those don't seem to exist.

I've thought of

  1. Switching to
    , but eventually I'll be converting to JSONP and I don't think
    supports that?

  2. Putting the
    and other DOM manipulation in a script tag within the returned data.

I suspect #2 is the recommended approach but wanted to do a sanity check here first. Has anyone experienced this?

Many thanks.

Answer Source

Although my previous answer worked, it didn't solve all your problems. I recommend something like:

var myDiv=document.createElement( 'div' );
// now do all of your initializing, passing in myDiv like $( myDiv )
  .find( '#BillingAddress' )

Hope this works!