0

Let's save I have an Element:

var el = $('mooo');

What's the easiest way to set its 'onclick' attribute or event (it may already have one)?

2 Answers 2

4

MooTools handles all its event adding with the addEvent() function:

var el = $('mooo');
el.addEvent('click',function(){ alert("I got clicked!"); });

Event names simply have the "on" prefix removed, ie. 'click','mouseover','mouseenter', etc.

1
  • yop, if JamesBrownlsDead wants to get rid of the events and replace them he should do like that : jsfiddle.net/WqgJE (maybe that's why he mentioned that the element may already have one?)
    – Romain
    Commented Mar 21, 2013 at 13:00
0
$('mooo').addEvent('click', function(e){
    // your code here.
    e.stop();
});

You mention, regarding events, that your element mooo may already have one. This should not affect this code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.