load() method deprecated?

Jquery

Jquery 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohanView Question on Stackoverflow
Solution 1 - JqueryFrédéric HamidiView Answer on Stackoverflow
Solution 2 - JqueryMohsin ShoukatView Answer on Stackoverflow
Solution 3 - JqueryPaul SweatteView Answer on Stackoverflow