I am attempting to add to a src of multiple images using jQuery as follows:
<img src="image.jpg">
to
<img src="image-thumb.jpg">
For some reason I can’t seem to wrap my head around this.
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, add a class to the img tags you want the script to affect (e.g.
<img src="image.jpg" class="foo">).Then, use jQuery’s
.attr()method to set thesrcattribute of all the img tags you want:If your images are named differently and you just want to add
-thumbto each one all at once, use a callback function:In this second code example, I am using a regular expression to find and replace the ending of the image URL.