Mike
Mike

Reputation: 33

jQuery colorbox only loads once

I have the following problem:

On my website I am using colorbox to display information in a lightbox and I have several divs which you can click to retreive the specific data you want to see. But the jQuery-script I am using only lets the user open a colorbox-screen once and doesn't work after that untill the page is reloaded.

$(".items").click(function(){
    $.colorbox({href:$(this).find("a.link",this).attr("href"),width:"900px",maxHeight:"70%"});
    return false;
});

Thanks in advance!

Upvotes: 0

Views: 1575

Answers (2)

Mike
Mike

Reputation: 33

Thanks everyone for your time, the working solution is:

$(".items").colorbox({ 
       href:function(){ return $(this).find("a.link").attr("href"); }, 
       width:"900px", 
       maxHeight:"70%" 
});

Thanks again!

Upvotes: 2

Samuel Liew
Samuel Liew

Reputation: 79032

You should not need to create the colourbox onclick. The plugin does all the event handling for you. Just initialize it this way:

$(".items").colorbox({
    href: $(this).find("a.link", this).attr("href"),
    width: "900px",
    maxHeight: "70%"
});

See the API and demos at http://jacklmoore.com/colorbox/

Upvotes: 2

Related Questions