load() method deprecated?
JqueryJquery Problem Overview
I was browsing through the jQuery api and noticed that the load method is on the deprecated list.
> Categories: Deprecated | Events > Document Loading
I usually use this method to check if images are completly loaded. Why is it deprecated? And what am I supposed to be using instead?
Jquery Solutions
Solution 1 - Jquery
See bug #11733, which documents this deprecation:
> The .load()
method is an ambiguous signature, it can either be an ajax
> load or attach/fire a "load" event. CCAO cannot tell them apart since
> it's a dynamic decision based on arguments.
To avoid ambiguities related to the method's signature, it is now recommended to use on() instead. For instance:
$("selector").load(function() {
// ...
});
Should become:
$("selector").on("load", function() {
// ...
});
Solution 2 - Jquery
load function deprcated in jQuery alternative of it is on which you can use like
$("iframe").on("load",function()
{
alert("on loaded iframe");
});
this work perfect for jquery-3.1.1.
Solution 3 - Jquery
If load
does not work as expected, an alternative is:
$(window).one("scroll", foo);
Or
$(window).one("scroll", function(){/*...*/});
Specifically, scroll event binding is useful in Android when DOMContentLoaded
doesn't work as expected, and IE8 and below when onreadystatechange
does not work as expected.
References