July 2011
Intermediate to advanced
276 pages
5h 11m
English
Remember mybutton? We will be using that as our trigger again.
<input type="button" id="mybutton" value="Greet Me!"/>
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
});
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.