What is the best way to reduce this jQuery code?
<p>I am new to jQuery, and currently have this repetitive code I would like to reduce, however I am not sure what is the best way.</p>

<p>It is exactly the same, just using different css selectors...</p>

<pre><code>$(".product-contain").find("a:has(img)").attr('data-fancybox-group', 'gallery').fancybox({
    wrapCSS    : 'fancybox-custom',
    closeClick : true,

    openEffect : 'none',

    helpers : {
        title : {
            type : 'inside'
        },
        overlay : {
            css : {
                'background' : 'rgba(238,238,238,0.85)'
            }
        }
    }
});

$(".page-id-31").find("a:has(img)").attr('data-fancybox-group', 'gallery').fancybox({
    wrapCSS    : 'fancybox-custom',
    closeClick : true,

    openEffect : 'none',

    helpers : {
        title : {
            type : 'inside'
        },
        overlay : {
            css : {
                'background' : 'rgba(238,238,238,0.85)'
            }
        }
    }
});
</code></pre>

<p>I tried doing it the following way...</p>

<pre><code>$(".product-contain, .page-id-31").find("a:has(img)").attr('data-fancybox-group', 'gallery').each(function(){ 
    $(this).fancybox({
        wrapCSS    : 'fancybox-custom',
        closeClick : true,

        openEffect : 'none',

        helpers : {
            title : {
                type : 'inside'
            },
            overlay : {
                css : {
                    'background' : 'rgba(238,238,238,0.85)'
                }
            }
        }
    });
});
</code></pre>

<p>...however when I do it this way, the attribute 'gallery' does not work (using the fancybox script dynamically). The purpose of the attribute is so users are able to go to the next or previous image while viewing the gallery. Although this attribute appears in the source code, it does not seem to work. </p>

<p>A link to the page.. <a href="http://noteha.co.uk/dev/products/" rel="nofollow">http://noteha.co.uk/dev/products/</a></p>

<p>I would be grateful for any other suggestions.</p>
