Created
September 19, 2012 11:00
-
-
Save jbgutierrez/3749045 to your computer and use it in GitHub Desktop.
HTMLElement.click behaviour
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
<a id='clickMe' href='#'>Click me</a> |
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
$a.click(); | |
1st jquery handler | |
2nd jquery handler | |
inline handler | |
$a.trigger('click'); | |
1st jquery handler | |
2nd jquery handler | |
inline handler | |
a.click(); | |
Native click was call | |
inline handler | |
1st jquery handler | |
2nd jquery handler | |
user click... | |
inline handler | |
1st jquery handler | |
2nd jquery handler |
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
var a = document.getElementById('clickMe'), | |
$a = $(a), | |
oldClick = HTMLElement.prototype.click; | |
HTMLElement.prototype.click = function(){ | |
console.log(" Native click was call"); | |
oldClick.apply(this); | |
} | |
a.onclick = function(){ | |
console.log(" inline handler") | |
}; | |
$a.click(function(){ | |
console.log(" 1st jquery handler"); | |
}).click(function(){ | |
console.log(" 2nd jquery handler"); | |
}); | |
console.log("$a.click();"); | |
$a.click(); | |
console.log("$a.trigger('click');"); | |
$a.trigger('click'); | |
console.log("a.click();"); | |
a.click(); | |
console.log("user click..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment