Click Only Once with MooTools

Earlier I have covered few articles related to event binding using MooTools. Here you can see the basic things which we need to know for MooTools.

So when you are working with any JavaScript framework the adding an events is comman task. All framework has their own set of events which we can bind to elements. With MooTools you can bind/implement your custom events also. If you are not sure how to achieve this then you can refer to this article for the same.

Upto now I have explained about assigning an events. When you assign event then it will remain assigned untill you remove the events.

For example, If I have assigned click event then it will executed every time you click on that element. This is the comman thing. But what if you want to click only once?

Yes this is what today’s article is about. I will show you the trick with which you can assign event but that only once using MooTools.

Make sure that you have included MooTools More to make this happen.

Normally we can assign click events using the event name “click“, but when you want to make it only once then that event should looks like “click:once“.

I have prepared live demo for this also but before this have a look at this code block for the same.

window.addEvent("domready", function(){ $("element_id").addEvent("click:once", function(){ // will be called only once..... }); });
  window.addEvent("domready", function(){
    $("element_id").addEvent("click:once", function(){
    // will be called only once.....

Have a look at live demo for this trick also.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: