Would there be a racing issue with html() though? I believe that is not an asynchronous method, so it would have to complete before the next chained method.

-- Josh


----- Original Message ----- From: "hedgomatic" <hedgoma...@gmail.com>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Saturday, July 04, 2009 9:34 AM
Subject: [jQuery] ready() to bind post-ajax events



I haven't seen much mention of this on the web, and only recently
discovered it works.... not sure if this is somehow bad practice or
just a lesser known trick, but lately I've been chaining .ready() at
the end of .html() when I want to bind events to new ajax data... I
presume it's much more efficient than live(), and avoids racing
issues. EG:


$.ajax({
   type: 'POST',
   url: 'myPage.html',
   success: function(c){
        $(".response").html(c).ready(function() {
    bindNewEvent(".response a");

         });
});

function bindNewEvent(o) {
    $(o).click(funciton() {  ...etc...  });
};



There's infinite docs about using .ready() to process the document,
but not returning HTML. Passing the above along should anyone find it
useful or have insight onto why it's seemingly not mentioned elsewhere.

Reply via email to