Dynamically replace image source with jQuery

I’m trying to replace the default Yelp star rating image for businesses with one of my own. To do so I need to find the corresponding image source for each of the possible 5 images that could have loaded. And then, based on that I need to load in the proper image I’ve created.

<div id="starRating">
    <img src="http://yelp-star-1.png"/>
</div>

So, yelp-star-1.png would be replaced with my-star-1.png. So on and so forth. This is probably pretty simple, but I’m new to jQuery and everything I’ve found has not worked properly. Your expertise is very much appreciated!

Leave a Comment