I only need to check that the page is loaded (without dynamic objects that might be modified after page appears fully)
I know JQuery's function: "ready()"
Will this function be relevant in the described-above case? Is there another / better way?
I only need to check that the page is loaded (without dynamic objects that might be modified after page appears fully)
I know JQuery's function: "ready()"
Will this function be relevant in the described-above case? Is there another / better way?
Share Improve this question edited Jun 30, 2013 at 14:09 Sigalit asked Jun 30, 2013 at 13:46 SigalitSigalit 2091 gold badge4 silver badges9 bronze badges 2-
1
window.onload
is not a jQuery function. Concerning it - have you seen the documentation? – John Dvorak Commented Jun 30, 2013 at 13:48 - you're right sorry , I meant ready function.. – Sigalit Commented Jun 30, 2013 at 14:11
2 Answers
Reset to default 12window.onload
isn't a jQuery function, it's a DOM event.
If using jQuery the best way to check whether the page is loaded is to handle the ready event which can be done in various ways
Shortest
$(function() {
// DOM initialized
});
Short
$.ready(function() {
// DOM initialized
});
Longer
$(document).ready(function() {
// DOM initialized
});
Longest
jQuery(document).ready(function() {
// DOM initialized
});
Just to mention that you have an alternative to jQuery' methods . You can use pure JavaScript solution:
window.addEventListener("load", function load(event){ // defining load event listener
window.removeEventListener("load", load, false); //remove listener, no longer needed
// window is loaded , you can use its DOM
},false);
This way is good in cases when you , for example , have small/lightweight pages and to load external libraries/frameworks is absolutely unnecessary .
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745334982a4623060.html
评论列表(0条)