javascript - Changing the image source using jQuery

Published: 04 March 2023
on channel: Code Samples
454
1

#short
#javascript
#jquery
#image
My DOM looks like this:
div id="d1"
div class="c1"
a href="#"img src="img1_on.gif"/a
a href="#"img src="img2_on.gif"/a
/div
/div

When someone clicks on an image, I want the image src to change to img src="imgx_off.gif" where x represents the image number 1 or 2.
Is this possible or do I have to use CSS to change the images?
attr(): http://api.jquery.com/attr/


On this page of the site you can watch the video online javascript - Changing the image source using jQuery with a duration of hours minute second in good quality, which was uploaded by the user Code Samples 04 March 2023, share the link with friends and acquaintances, this video has already been watched 454 times on youtube and it was liked by 1 viewers. Enjoy your viewing!