I have the following code:
<div class="flex-gametypes">
<div><img src="assets/images/game/one.png"></div>
<div><img src="assets/images/game/two.png"></div>
</div>
I have the following image files:
assets/images/game/one.png
assets/images/game/two.png
assets/images/game/one-highlight.png
assets/images/game/two-highlight.png
What I want to do:
When I click on one.png, the code must rename the file to one-highlight.png.
When I click on it (one.png) again, it should continue to be one-highlight.png.
But if I were to click on two.png, then one-highlight.png should be back as one.png and two.png should now be two-highlight.png
So, this is what I tried: (I got some help from this question).
$(document).ready(function(){
$(".flex-gametypes img").click(function(){
$(this).attr('src', $(this).attr('src').replace('-hightlight.png') + '');
$(this).attr('src', $(this).attr('src').replace(/\.png/, '') + '-highlight.png');
});
});
But this does not display the desired result. So how can I achieve this effect?