Responding to both CLICK and MOUSEOVER

Getting ready

Remember mybutton? We will be using that as our trigger again.

<input type="button" id="mybutton" value="Greet Me!"/>

How to do it...

Using the same triggering INPUT widget and hello-saying lines of code from earlier in this chapter, we are ready to add multiple events to mybutton.

$('mybutton').addEvents({
'click':say_hello,
'mouseover':say_hello
});

How it works...

After moving the lines of code that must be reused, the lines that greet our user in four different ways, we have functionally encapsulated these actions. We then use MooTools' Element.addEvents() to add multiple event listeners that will call the say_hello() function.

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.