Click Only Once with MooTools

  • Avinash
  • 2
  • Mar 01, 2012
  • Web Development

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 currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.

View all posts by: