开发者

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

开发者 https://www.devze.com 2023-01-08 20:14 出处:网络
I think this question is better served with an example. I have the following code: $.get(开发者_JAVA技巧\'path/\'+id,function(data){

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

精彩评论

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