Matt Cowley
Matt Cowley

Reputation: 2373

jQuery 3.0 $(window).load(function(){});

so jQuery 3.0 was released today, and for some reason the following code no longer works on my site:

$(window).load(function() {});

Can anyone suggest how I fix this or an alternative that actives when /everything/ is loaded?

Upvotes: 46

Views: 47007

Answers (1)

gaetanoM
gaetanoM

Reputation: 42054

Reading from breaking-change-load-unload-and-error-removed:

Breaking change: .load(), .unload(), and .error() removed

These methods are shortcuts for event operations, but had several API limitations. The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $(img).on("load", fn).

Therefore, you need to change:

$(window).load(function() {});

to:

$(window).on("load", function (e) {})

Upvotes: 114

Related Questions