views:

18

answers:

1

I think this question is better served with an example. I have the following code:

$.get('path/'+id,function(data){
$('#mydiv').html(data);
$('.editable').button().click(function(){
//process here
});
});

And it works just fine; however, I think it would be more optimal to only go through "mydiv" when I call $('.editable') rather than through the whole page without even finding "mydiv" again. Example of what I think should work:

$('#mydiv').html(data).$('.editable').button().click(function(){
//process here
});
});

In other words, I suppose after completing its work with the html function I can perform another action on this div. Is this possible? Sorry if this seems odd and convoluted.

Thanks!

+3  A: 
var my_div = $('#mydiv');
$.get('path/'+id,function(data){
    my_div.html(data)
        .find('.editable')
        .button()
        .click(function(){
            //process here
        });
});
Stephen