I am currently trying to change the number at the end of a image path on click.
$(".container-button").click(function(){
$("img.picture").each(
function(){
var p = $(this).attr('src');
var new_image = p.replace('3.jpg' || '2.jpg' || '1.jpg', '4.jpg');
$(this).attr('src',new_image);
}
);
});
If you take a look at my code I do the following:
- on click i search the class for the image source and store it in a variable
- I create a new variable that looks for the end of the image file for a set of filenames, replaces it with 4.jpg, and stores it in a variable new_image.
- I look for the source attribute and switch it for what is stored in new_image.
What im seeing is that it only looks to replace if it finds the first filename in the set but the others are ignored.
what am I doing wrong?