[Update:] This question is related to: what does jQuery's click() do?
http://stackoverflow.com/questions/3130539/jquerys-click-is-not-clicking
The following code:
<div id="oneDiv">
some content
</div>
<p>
<a href="http://www.google.com" id="clickme">Click Me</a>
</p>
[ ... ]
onload = function() {
$('#clickme').click(function() {
$('#oneDiv').css({border: '6px dotted #07d'})
});
document.getElementById('clickme').onclick = function() {
document.getElementById('oneDiv').style.color = 'green';
}
document.getElementById('clickme').addEventListener("click", function() {
document.getElementById('oneDiv').style.background = '#ffc';
}, false); // bubbling phase
setTimeout(function() {
$('#clickme').click();
}, 3000);
}
If you click on the link, then the browser will
1) change border to 6px dotted blue
2) change text inside the div to be green
3) change background of div to offwhite
4) go to www.google.com
but if you wait and let the setTimeout()'s function to kick in, then it will only do the
$('#clickme').click(function() { })
onclick = function() { ... }
it will not do the addEventListener one, and it will not follow the link. (IE 8 won't allow addEventListener by the way)
So is it true? jQuery's click(), which is the same as trigger('click') will only fire off event handlers registered through itself and the DOM level 0 event handler?