Here is how I am calling the function:
function addClickHandlers() {
$("#codesNext", this).click(function(){
$("#availcodes").load("includes/populate_table.php", { start: $
("#start").val() }, addClickHandlers);
});
$(".code").each(function(index) {
$(this).unbind(); });
$(".code", this).each(function(index) {
$(this).fancybox( { href: "manageCode.php?code=" + $
(this).attr("name") } );
addClickHandlers();
});
}
$(document).ready(addClickHandlers);
and this is a sample table row:
<tr class="code" id="rowevenover" name="278">
I also tried it without calling from the addClickHandlers function and
just putting it inside $(document).ready, but this didn't work
either. I tried it this way to see if the handlers just needed
reapplied after the content refreshed...
any ideas? thanks in advance!
First add the FancyBox javascript to your page or JS file as you would
normally. The below contains JS to bind FancyBox to a link with an ID
of "openFancyBox" as well as JS to trigger FancyBox when the user
clicks a link with an CLASS of "clickFancyBox". I'm using jQuery's
live() function so that any link that gets added dynamically with a
CLASS of "clickFancyBox" will ensure the FancyBox gets opened.
<script>
$("a#openFancyBox").fancybox();
$("a.clickFancyBox").live('click',function() {
$('a#openFancyBox').trigger('click');
});
</script>
<a id=""openFancyBox href="[IMAGE_URL]"></a>
Then when you want to have any dynamically generated content trigger
simply add an anchor tag with a CLASS of "clickFancyBox". Like this:
<a class="clickFancyBox" href="[IMAGE_URL]">Open Fancy Box</a>
When a user clicks the above link it will trigger a click on the link
with FancyBox binded to it, and open FancyBox.
Hope that helps!
-Brett DeWoody
<script>
$("a#openFancyBox").fancybox();
$("a.clickFancyBox").live('click',function() {
$('a#openFancyBox').trigger('click');
});
</script>
<a id="openFancyBox" href="[IMAGE_URL]"></a>
The difference being the quotes around the ID of the anchor tag.