开发者

Jquery: How to process a div after you have appended or set data to it optimally

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

$.get(开发者_JAVA技巧'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!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜