Is there a way to use jquery to select all checkboxes on a page that have an associated click event? I considered adding a class, for instance HasClickEvent, that I could use to identify such classes, but I am editing a huge script where click events are sporadically added all over the place and I think this would probably end up being messier, so a single jQuery call would be perfect
4 Answers
jQuery.each($('input[type=checkbox]').data('events'), function(i, event){
jQuery.each(event, function(i, handler){
if(handler.type.toString() == 'click')
{
// do something
}
});
});
2 Comments
Jordan Wallwork
This looks pretty good, do you know what toString() will return in the case of no associated event?
Abhijit
This checks the events that have been bound, so in case of no bound event, this wont be running. By the way, this is good solution.
A quick google reveals this plugin, but it's pretty old. You may be able to read the code and see how they are achieving it though :D