Last active
September 8, 2017 11:53
-
-
Save mkdizajn/9190429eb5e50e85e98c67d0de27cd82 to your computer and use it in GitHub Desktop.
How easily to hook into native jQuery event,, I have built example to alter attr method, but it can easily be 'addClass', 'removeClass' etc..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
// save Original attr method! | |
var orgAttr = $.fn.attr; | |
// Change attr | addClass | similar method to be able to hook to JQ event | |
$.fn.attr = function(){ | |
var result = orgAttr.apply( this, arguments ); // Execute the original method. | |
$(this).trigger('customTriggerName'); // trigger custom event on element | |
return result; // return the original result | |
} | |
// HOOK @ ATTR binded event | |
$('.element').bind('customTriggerName', function(event){ | |
// do some custom stuff here! | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment