# if else statement

**URL:** https://forum.kirupa.com/t/if-else-statement/635200
**Category:** web dev
**Created:** [September 1, 2016, 12:21pm UTC](https://forum.kirupa.com/t/if-else-statement/635200 "2016-09-01T12:21:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![uxk83961](https://avatars.discourse-cdn.com/v4/letter/u/8edcca/32.png) [@uxk83961](https://forum.kirupa.com/u/uxk83961)
#### Post date: [September 1, 2016, 12:21pm UTC](https://forum.kirupa.com/t/if-else-statement/635200/1 "2016-09-01T12:21:25Z")

</div>

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.  
Thanks

---

<div class="post-metadata">

### Author: ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)
#### Post date: [September 1, 2016, 5:52pm UTC](https://forum.kirupa.com/t/if-else-statement/635200/2 "2016-09-01T17:52:12Z")

</div>

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](https://www.kirupa.com/html5/handling_events_for_many_elements.htm)

Does this help? 🙂
