Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-02-03
2
Medium Priority
?
64 Views
Last Modified: 2015-02-14
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" >
0
Comment
Question by:JJ2357
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Big Monty earned 2000 total points
ID: 40586950
you can try something like this using jquery:

var source = '';
$('input[id*="thumb_"]').each() {
     source = $(this).attr("src").replace(("md", "lg" );
    $(this).attr("src", source);
});

Open in new window

0
 
LVL 11

Expert Comment

by:Jeffrey Dake
ID: 40587839
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question