jQuery.click() vs onClick

Using $(‘#myDiv’).click(function(){ is better as it follows standard event registration model. (jQuery internally uses addEventListener and attachEvent). Basically registering an event in modern way is the unobtrusive way of handling events. Also to register more than one event listener for the target you can call addEventListener() for the same target. http://jsfiddle.net/aj55x/1/ Why use addEventListener? (From MDN) addEventListener is the way to register an event listener as specified in W3C DOM. Its … Read more

window.onload vs document.onload

When do they fire? window.onload By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.). In some browsers it now takes over the role of document.onload and fires when the DOM is ready as well. document.onload It is called when the DOM is ready which can be prior to images and other external content … Read more