Reputation: 1733
I cannot get a document.load event to fire, and in jQuery 2+, I can't get the document.ready to fire either. How can I make document.ready work in jQuery 2+, and how can I make .load work?
Thanks!
Fiddle: http://jsfiddle.net/2x7SP/2/
(function($) {
$(document).ready(documentReadyFunction);
$(document).load(afterPageLoad);
function documentReadyFunction() {
$('#readytext').val('READY');
}
function afterPageLoad () {
//alert ('loaded');
$('#loadtext').val('LOAD');
}
})(jQuery);
Upvotes: 1
Views: 93
Reputation: 30993
The load
event is fired by the window, not by document. By changing it, it works fine.
Code:
(function ($) {
$(document).ready(documentReadyFunction);
$(window).load(afterPageLoad);
function documentReadyFunction() {
$('#readytext').val('READY');
}
function afterPageLoad() {
//alert ('loaded');
$('#loadtext').val('LOAD');
}
})(jQuery);
jQuery 2 dropped the support to old IE versions http://blog.jquery.com/2013/04/18/jquery-2-0-released/ :
As promised, this version leaves behind the older Internet Explorer 6, 7, and 8 browsers. In return it is smaller, faster, and can be used in JavaScript environments where the code needed for old-IE compatibility often causes problems of its own. But don’t worry, the jQuery team still supports the 1.x branch which does run on IE 6/7/8. You can (and should) continue to use jQuery 1.9 (and the upcoming 1.10) on web sites that need to accommodate older browsers.
If you need to support IE<9 you have to switch to jQuery 1.x.
Ref: http://jquery.com/browser-support/
Demo: http://jsfiddle.net/IrvinDominin/7CpF7/
Upvotes: 3
Reputation: 9151
This works for me:
function documentReadyFunction() {
$('#readytext').val('READY');
}
function afterPageLoad() {
$('#loadtext').val('LOAD');
}
$(document).ready(documentReadyFunction);
$(window).load(afterPageLoad);
Upvotes: 1
Reputation: 2605
There are two problems:
document.load
. The load
event is only fired by elements associated with a URL, such as an image or an iframe, or the window
object, which is probably the one you want to use.load
handler, which means that load
has already fired.The code is fine as long as you replace document.load
with window.load
:
$(window).load(afterPageLoad);
And don't wrap the jQuery in the load event. Fixed fiddle: http://jsfiddle.net/tNUv2/
Upvotes: 2