1

I'm looking for a way to add an underscore to a filename (and remove "_" from sibling) so it'll show a new "clicked" image.

for example:

Beginning with "my_image1_.png" (which means it's clicked), I want when I click on "my_image2.png" to change to "my_image2_.png"

Thanks in advance!

 $('.img_icons_result').click(function(){
  $(this).html($(this).html().replace('_.png', '.png'))
   return false;
 });
<img src="img/icons/my_image1.png" class="img_icons_result" />
<img src="img/icons/my_image2.png" class="img_icons_result" />
<img src="img/icons/my_image3.png" class="img_icons_result" />
<img src="img/icons/my_image4.png" class="img_icons_result" />

1 Answer 1

1

You shouldn't use html. You should just replace the src attr

$('.img_icons_result').click(function(){
   $(this).attr('src', $(this).attr('src').replace('_.png', '.png'));
   return false;
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.