Having problems with a (probably) simple task of passing a variable as a src of an image.
The variables are defined at random from an array, and then if URL criteria is met then that random variable is assigned as the src of the image.
jQuery:
var imgpathnamesfor7offers = ["offers1.jpg", "offers2.jpg", "offers3.jpg", "offers4.jpg"];
var randompathname = imgpathnamesfor7offers[Math.floor(Math.random() * imgpathnamesfor7offers.length)];
var produrl = jQuery(location).attr('href');
var icatRef = produrl.split("/")[4];
if (icatRef == "shark-steam-cleaning") {
jQuery("#prodpagesliderbar-img").attr("src", jQuery("#prodpagesliderbar-img").attr("src").replace(randompathname));
}
Can anyone see what I'm doing wrong? Console appends 'undefined' to the end of the src.
instead of this:
jQuery("#prodpagesliderbar-img").attr("src").replace(randompathname)
this should be:
jQuery("#prodpagesliderbar-img").attr("src", randompathname)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.