sushil bharwani
sushil bharwani

Reputation: 30187

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. I 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.

Upvotes: 1

Views: 1282

Answers (3)

Yasen Zhelev
Yasen Zhelev

Reputation: 4045

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"});
});

Upvotes: 2

Matt G
Matt G

Reputation: 1

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();
});

Upvotes: 0

Semyazas
Semyazas

Reputation: 2101

add a class to the links. For example .lightmeup

then you do:

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

Upvotes: 0

Related Questions