Web Development

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.

[cc lang=”javascript”]
window.addEvent(“domready”, function(){
$(“element_id”).addEvent(“click:once”, function(){
// will be called only once…..
});
});
[/cc]

Have a look at live demo for this trick also.

Shares:
  • […] will show you the trick with which you can assign event but that only once using MooTools.    Javascript Read the original post on DZone… […]

    Reply
  • […] Once with jQuery Posted by Avinash on Mar 4, 2012 in Javascript, jQuery | 0 comments Have a look at this previous article which shows the trick with which you can bind the event to any HTML element but only once. Here is […]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *