jquery - Why doesn't $('document').load() fire? -


i replaced .ready() .load():

$('document').load(function(){   alert('test'); }); 

but nothing happens. go ready() , works fine. there isn't in document. it's blank html file.

what doing wrong?

$(document) not $('document') when selecting document because there no <document> element.

additionally, document doesn't fire load event. window fires load event. should using $(window).load(...).

the reason why $('document').ready() works because .ready() doesn't use selector context, , api should have been $.ready(...). avoid $(document).ready() , stick aliasing shorthand version:

jquery(function ($) {     ... }); 

also, aware binding document.ready after document ready still fire callback. binding window.onload after window has loaded will not fire callback.

$(document).ready(function () {    alert('document selector works');  });    $('document').ready(function () {    alert('invalid selector works');  });    $().ready(function () {    alert('no selector works');  });    $(window).load(function () {    alert('window load works!');        $(window).load(function () {      alert("load has fired, doesn't work");    });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -