JQuery for each anchor href replace thumbnail img src
Dont laugh, this is my weak attempt at trying to get each anchor links href and replacing the image source for .product-thumbnail img
<script>
jQuery.noConflict();
jQuery(document).ready(function($) {
//var findImage = $('dd.variation-File ul li a').attr('href');
//get the anchor link to image
x=$('dd.variation-File ul li a').toArray();
//replace default thumbnail with anchor link from x
y=$('td.product-thumbnail img').toArray();
y.each().attr['src'].replace(this, x);
});
</script>
On our cart page there is a table that displays cart info. There are multiple image (previews) and if an image was uploaded then there is a dd.variation-File ul li
with an anchor, I simply am trying to write a script that if dd.variation-File ul li a
exists, replace the img src for .product-thumbnail img
with the href found in dd.variation-file ul li a
Thanks for helping out a noob :)
I think you need this:
y.each(function(){
$(this).attr('src',$(this).attr('src').replace(this, x));
});
But I don't know what it will do, since replace
accepts a string instead of an array.
上一篇: memmove和memcpy有什么区别?