I need a hasEvents()
method like
var someBool = hasEvents($("#myelement"));
that returns true
if there are some bound events to any of the element's event handlers.
right click on the target element -> select " Inspect element " Scroll down on the right side of the dev frame, at the bottom is ' event listeners '. Expand the tree to see what events are attached to the element.
bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.
In short: . bind() will only apply to the items you currently have selected in your jQuery object. . live() will apply to all current matching elements, as well as any you might add in the future.
jQuery provides a method . on() to respond to any event on the selected elements. This is called an event binding.
have you taken a look at the hasEvent()
plugin? the code is pretty small:
(function(A) {
A.fn.hasEvent = function(C) {
var B = this.data("events");
return( B && B[C] )
}
}) (jQuery)
for your specific purpose you could modify it slightly:
(function($) {
$.fn.hasEvents = function() {
return new Boolean(this.data('events') );
}
}) (jQuery);
$('#someDiv').click(function() {
alert('new event');
});
$('#someDiv').hasEvents(); // true
$('#someOtherDiv').hasEvents(); // false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With