开发者

Unable to use colorbox in ajax results suggest what to do?

I am having a page on which jQuery and jQuery colorbox libraries are included. 开发者_如何学CI have some functionality which brings a set of results (links) on this page using ajax. On clicking of links (that come on the fly) i want to open colorbox. Please suggest how could i do it.


You should use live() method to assign the click handler to dynamically created elements like your links. If you provide some code I could show you how to make it.

$('a.yourlinkclass').live('click', function(){
  $.colorbox({href:"html_to_show.html"});
});


add a class to the links. For example .lightmeup

then you do:

$('.lightmeup').click(function(){
$(this).colorbox(/*values and attributes go here*/)
})


You would need to rebind your colorbox calls in the callback function once the ajax links have loaded in.

Something like:

$.get('ajax_links.php', function(data){
    $('#holder').html(data);
    $('#holder a').colorbox();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜