Reputation: 1654
As question describe all, but just for clarification, I want to do a common stuff like alert
value when i click on any button.
Please suggest a solution in YUI3 only because i am using YUI3.
Upvotes: 0
Views: 115
Reputation: 46
There is a more efficient way to do it:
Y.delegate('click', function(e) { ... }, 'body', 'button');
This attaches a single event handler to the body instead of attaching a separate event handler to each button.
YUI Documentation - delegation
Upvotes: 3
Reputation: 632
If I understand what you want, you want to bind every button to the same event? Like say a user clicks any button you want to catch it? If so here is how it's done.
Y.all('button').on('click', function(e){
//handle event here
//e.preventDefault(); if needed to prevent default browser behavior
});
This could be bound to any event for more details on events YUI Events should be useful. Hope this helps.
Upvotes: 1