if else statement

I want to create a scenario in a webpage using javascript whereby there are two different pictures on stage, and when the user hits (mouse over) one of the image, there is a message that is displayed accordingly. How do we write a hitTest in javascript, and incorporate a conditional statement as well.

I am going to throw some jargon at you: The easiest way is to listen to a mouseover event on the images and display the appropriate text by modifying the DOM. Here is a simple example for just one button:

var button = document.querySelector("#button");

button.addEventListener("mouseover", displayText, false);

function displayText(e) {
    alert("button clicked!");

For multiple buttons, you need a way to uniquely identify them. The ID value is one valid way of doing that. You can listen for events on multiple buttons by using an approach described here: https://www.kirupa.com/html5/handling_events_for_many_elements.htm

Does this help? :slight_smile:

1 Like