Search code examples
javascriptlivejquery

How would I integrate .live() into this function?


I want to integrate .live() into this function:

$('a.oembed').each(function(){
    $(this).embedly({maxWidth:400,'method':'replace'}).bind('embedly-oembed', function(e, oembed){ 
        $(this).parent().append($("<img>", { src: oembed.thumbnail_url, width:200 })).children('img').wrap('<div class="thumbnail_border" />');

    });
});

so that it will be triggered once new elements are loaded. How would I do this?


Solution

  • not sure why use use each at first place..

    $('a.oembed').embedly({maxWidth:400,'method':'replace'}).live('embedly-oembed', function(e, oembed){ 
            $(this).parent().append($("<img>", { src: oembed.thumbnail_url, width:200 })).children('img').wrap('<div class="thumbnail_border" />');
        });
    

    If you want the embedly method to take different values while applying it then you should use the each just for that part

    $('a.oembed')
        .each(function(){
                   $(this).embedly({maxWidth:400,'method':'replace'});
                 })
        .live('embedly-oembed', function(e, oembed){ 
                   $(this).parent()
                          .append($("<img>", { src: oembed.thumbnail_url, width:200 }))
                          .children('img')
                          .wrap('<div class="thumbnail_border" />');
                 });