You can use a single script like:
$(document).ready(function() { $("a.fancybox").fancybox(); });
Then, when you create your galleries, just add a different rel attribute for each gallery, but the same class="fancybox" , for example:
<a class="fancybox" href="images/01.jpg" rel="gallery01">image 01</a> <a class="fancybox" href="images/02.jpg" rel="gallery01">image 02</a> <a class="fancybox" href="images/03.jpg" rel="gallery01">image 03</a> <a class="fancybox" href="images/04.jpg" rel="gallery02">image 04</a> <a class="fancybox" href="images/05.jpg" rel="gallery02">image 05</a> <a class="fancybox" href="images/06.jpg" rel="gallery02">image 06</a>
When you click on any image (for example, image 01), it displays in the gallery (Fancybox) only those elements with the same rel attribute (images 02 and 03, as, for example, in the example above + image 01)
With fancybox v2.x you do not need to use jQuery live() , as suggested by @sczizzo, since fancybox v2.x already supports both existing and dynamically added elements
Last note : do not use an identifier for more than one element. The identifier must be unique and you must not use the same identifier twice or more times in the same html document. Check out the http://fancyapps.com/fancybox/#support FAQ # 6 for more
source share