O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required