Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  169] [ 6]  / answers: 1 / hits: 16660  / 5 Years ago, sun, february 24, 2019, 12:00:00

I have an image in my HTML code, and I want to make it so that when my mouse is hovering over the image, it will change to the other image, and when the mouse is not hovering over the image, it switches back to the default. How do I program this in a <script> tag?


More From » html

 Answers
8

No <script> tag necessary. Use onmouseover and onmouseout to change the image source.



onmouseover will execute an action when your mouse goes over the image. In this case, we use this.src to set the image src to another image.



onmouseout will execute an action when your mouse goes out of the image. In this case, we use this.src again to set the image to the default image.





<img title=Hello src=https://static.independent.co.uk/s3fs-public/thumbnails/image/2017/09/12/11/naturo-monkey-selfie.jpg?w968h681 onmouseover=this.src='https://www.ctvnews.ca/polopoly_fs/1.4037876!/httpImage/image.jpg_gen/derivatives/landscape_1020/image.jpg' onmouseout=this.src='https://static.independent.co.uk/s3fs-public/thumbnails/image/2017/09/12/11/naturo-monkey-selfie.jpg?w968h681' />




[#52544] Tuesday, February 19, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;