Jquery “live” gotchas with Colorbox

Leave a comment

September 13, 2011 by temebele

If you have a script like the following with large_popup as the css class of your hyperlink.

$(document).ready(function() {
    $(". large_popup").live('click', function(e) {
        e.preventDefault(); 
        $(this).colorbox({
            overlayClose: false,
            close: "x",
            open: true,
            transition: "none",
            width: "995px"
        });
    });
});
Change it to:
$(document).ready(function () {
      $(".large_popup").live('click', function (e) {
           e.preventDefault();
            $.colorbox({href: this.href,
                overlayClose: false,
                close: "x",
                open: true,
                transition: "none",
                width: "995px"                
            });
        });
});
Otherwise, multiple colorbox calls fire everytime you click that link.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: