Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Created September 19, 2012 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgutierrez/3749045 to your computer and use it in GitHub Desktop.
Save jbgutierrez/3749045 to your computer and use it in GitHub Desktop.
HTMLElement.click behaviour
<a id='clickMe' href='#'>Click me</a>​
$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
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