The usual way to assign color box functionality on a link is like this:
$("a.colorbox").colorbox({ transition: "elastic" });
Newly added items are not bound in this way though.
How can I add colorbox to dynamically created
elements too?<a class="colorbox"></a>
This post is old but this may help others: simonthetwit solution is ok, but you'll need to click the trigger link twice. Colorbox can be called directly, so this should work:
Cheers!
You could also try this:
I think it's a little cleaner then using the
fn
command.As live is depreciated, you should use on
This code also allows grouping.
The method described here is to live-bind to the
click
event on the elements you're interested in (such as.colorbox
in this instance) and call the colorbox library function in the handler:I was having the same problem as @sunburst with having to click the trigger link twice. Used the same code, but
.delegate()
instead of.live()
. Solved everything and cleaned up my jQuery nicely!Nice explanation here: http://www.alfajango.com/blog/the-difference-between-jquerys-bind-live-and-delegate/
Here was the solution I found to avoid the needing of clicking twice the link to fire the event: