Makes no sense to use .one()
in any of the combination document ready
or window load
.
api.jquery.com/one:
Attach a handler to an event for the elements. The handler is executed at most once per element per event type
you clearly don't expect the ready
or load
to trigger twice. Those run once per session so it's quite silly to use .one()
for this (artificial) events.
Also it's good to know that:
$(document).one("ready", function(){
console.log("DOCUMENT SILLY ONE READY");
});
$(function(){ // (DOM ready shorthand)
console.log("DOCUMENT READY"); // not only will this one run...
});
// but also this is the order result:
// DOCUMENT READY
// DOCUMENT SILLY ONE READY
so to conclude, you only need
$(function(){
// DOM is ready to be manipulated
foo();
bar();
});
or:
$(window).load(function(){
// DOM, metadata, scripts, files, styles, images...etc are load and ready
foo();
bar();
});
and your functions will not run more than once.