Introduction to Programming Using JavaScript — Question 26

You are creating a dynamic HTML page by using JavaScript.
Your page has an image of the sun. When the user's mouse pointer moves across the image of the sun, the image should change to the image of the moon.
When the user's mouse pointer is no longer over the image should change back to the image of the sun.
You need to write the code for the image swap.
Which two events must you program for? (Choose two.)

Answer options

Correct answer: B, D

Explanation

The correct events to program for this functionality are onmouseover and onmouseout. The onmouseover event triggers when the mouse pointer hovers over the image, allowing the image to change to the moon, while the onmouseout event triggers when the mouse pointer leaves the image, allowing it to revert to the sun. The other options do not provide the necessary functionality for this specific behavior.