Link to home
Start Free TrialLog in
Avatar of JJ2357
JJ2357Flag for United States of America

asked on

How can I find and replace part of a url based on element id contains?

My page is a grid of products with several images.  The images each of unique id's that share a common prefix "thumb_".  I need to find each image based on each image whose id contains "thumb_" and replace the src from "_md" to "_lg".

Example:
<img id="thumb_1234_abc" src="http://www.mystore.com/images/product/1234_abc_md.jpg" >
<img id="thumb_5678_abc" src="http://www.mystore.com/images/product/5678_abc_md.jpg" >

Updated to:
<img id="thumb_1234_abc" src="http://www.mystore.com/images/product/1234_abc_lg.jpg" >
<img id="thumb_5678_abc" src="http://www.mystore.com/images/product/5678_abc_lg.jpg" >
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Might I recomend changing the above replace from "md", "lg" to "md.jpg", "lg.jpg". It seems like you are really trying to change the end of the url. This way you can avoid messing up and image that has the letters md anywhere else in the url.