What are the advantages of using jQuery's
$(window).blur(function() { ... })
to attach an event handler versus setting it directly with
window.onblur = function() { ... }
It seems that the latter is less robust because it only supports one blur handler, and when used with other packages, other code might override the window.blur
value with another function. However, couldn't this also happen with the jQuery implementation too, which presumably uses window.blur
as its underlying implementation?
EDIT: Several people have also mentioned the window.addEventListener
alternative, which can be used to add an 'onblur'
event apart from the methods above.