Search code examples
javascriptjqueryajaxyoutubecolorbox

Colorbox and ajax youtube - not working together?


I'm using ajax to get and create a list with youtube videos from specific user and jquery.colorbox as a jQuery lightbox.

I can't make them to work together :( Can someone tell me how to fix, please.

DEMO: http://dev.template-tuners.com/a/youtube.html

Thanks.


Solution

  • There are several issues with what you've done: First, remove the class cboxElement from your code. Second, don't query the document for all '.youtube' links on each iteration in $.each, it is very inefficient. Third, you can't query the document for '.youtube' if you haven't appended that HTML to the document yet.

    Move these lines:

    $(".youtube").colorbox({
        iframe:true, 
        innerWidth:640, 
        innerHeight:360,
    });
    

    To be the very statement thing in your show_my_videos function.