i need to replace a filename in a path. I found a few solutions for this but I couldnt get any of them to work with my particular situation.
I have 3 elements to work with here....
the trigger image: http://domainname.com/path/to/files/product_thumb_small/public/THUMB-1.jpg
the replaced image: http://domainname.com/path/to/files/product_preview/public/PREVIEW-IMAGE.jpg
the replaced href: http://domainname.com/path/to/files/product_full/public/FULL-IMAGE.jpg
So what I need to do is when I mouse over the trigger image it replaces the replaced image and replaced href image file names but keeps the path as it was.
so when I mouse over the trigger image eg:
<div class="product-img-thumb-small">
<a title="" href="">
<img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-4.jpg" />
</a>
</div>
this:
<a class="cloud-zoom" href="http://domainname.com/path/to/files/product_full/public/FULL-IMAGE.jpg">
<img src="http://domainname.com/path/to/files/product_preview/public/PREVIEW-IMAGE.jpg">
</a>
becomes this:
<a class="cloud-zoom" href="http://domainname.com/path/to/files/product_full/public/THUMB-4.jpg">
<img src="http://domainname.com/path/to/files/product_preview/public/THUMB-4.jpg">
</a>
Here is my HTML code:
<div class="product-preview-wrapper">
<div class="product-img-thumb">
<div id="wrap">
<a class="cloud-zoom" href="http://domainname.com/path/to/files/product_full/public/FULL-IMAGE.jpg">
<img src="http://domainname.com/path/to/files/product_preview/public/PREVIEW-IMAGE.jpg">
</a>
</div>
</div>
</div>
<div class="product-image-wrapper">
<div class="item-list">
<ul>
<li class="first">
<div class="product-img-thumb-small"><a title="" href=""><img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-1.jpg" /></a></div>
</li>
<li>
<div class="product-img-thumb-small"><a title="" href=""><img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-2.jpg" /></a></div>
</li>
<li>
<div class="product-img-thumb-small"><a title="" href=""><img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-3.jpg" /></a></div>
</li>
<li>
<div class="product-img-thumb-small"><a title="" href=""><img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-4.jpg" /></a></div>
</li>
<li class="last">
<div class="product-img-thumb-small"><a title="" href=""><img src="http://domainname.com/path/to/files/product_thumb_small/public/THUMB-5.jpg" /></a></div>
</li>
</ul>
</div>
</div>
I'm using jQuery. I have this so far:
$('.product-image-wrapper .product-img-thumb-small img').hover(function () {
var newImg = $(this).attr("src");
$(".product-preview-wrapper a.cloud-zoom").attr("href",newImg);
$(".product-preview-wrapper a.cloud-zoom img").attr("src",newImg);
});
But the issue is with the path.. I dont want ot replace the path.. just the image filename.
Any help with this is much appreciated.
Regards C
$('.product-image-wrapper .product-img-thumb-small img').hover(function () {})preview.attr('src').substring(0,preview.attr('src').lastIndexOf('/')+1 )but I dont see the point of pasting the things i tried that DONT work.