Getting imagename and make link from <img> with jQuery
Posted
by
Bulan
on Stack Overflow
See other posts from Stack Overflow
or by Bulan
Published on 2010-12-27T14:45:36Z
Indexed on
2010/12/27
14:54 UTC
Read the original article
Hit count: 157
With jQuery, I want to make all images under a specific path on a site clickable and showing a big image using Fancybox, which is a lighbox variant plugin for jQuery.
My small images are located under "images/products/small", the big ones under "images/products/big" and the imagename is always the same
The page is showing the image with the following code:
<img src="images/products/small/hat.jpg" alt="Nice hat">
What i want is some jQuery script that makes this into:
<a href="images/products/big/hat.jpg" class="fancybox"><img src="images/products/small/hat.jpg" alt="Nice hat"></a>
Maybe the part with setting class on the link tag can be skipped and just activate fancybox on the element directly with $(elm).fancybox();
I was looking around a bit and it looks like the jQuery functions "attr" and "wrap" might be useful, but with my currently limited jQuery skills I can't really connect the dots.
© Stack Overflow or respective owner