如何在Fancybox中为没有链接的图像设置组?

目前,我使用此代码将Fancybox应用于未由标记包装的一组图像:

 $("img[alt=lightbox]").each(function(){ $(this).fancybox({ href : $(this).attr('src') }); }); 

现在,我想将以这种方式添加的所有图像添加到同一组中。

我尝试过:

 $("img[alt=lightbox]").each(function(){ $(this).attr("data-fancybox-group", "gallery"); $(this).fancybox({ href : $(this).attr('src') }); }); 

没有运气,你有什么建议吗?