JQuery live () ... need to double-click to activate links?

I have the following bit of code, simply:

$(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({ overlayClose: false, onComplete: function() { $('#add_photos').submit(function(e) { // more stuff to do e.preventDefault(); }); } }); e.preventDefault(); }); }); 

However, it seems that this only works after clicking the TWICE link once. These links are dynamically added to the page ( a.add-photos-link ).

Why is this happening and what can I do to fix it so that it works after the first click?

+6
jquery click live
source share
1 answer

Your current code only creates a color link for the link. It does not open colorbox, so you need to double-click the link: once to create it and open it again.

You can use the open parameter ( as documented ) when creating a colorbox to open it immediately:

 $(this).colorbox({ open: true, overlayClose: false, onComplete: function() { // ... } }); 
+7
source share

All Articles