$(document).one('ready', function () {
doSomething();
});
Using .one ensures that this is done only once, and not repeatedly. It is possible to host multiple document.ready event listeners (if you need other events to run multiple times) if you are not overdoing it for readability.
.one is especially useful when you want a warning to appear when you first open a web page or when you install a mobile application for the first time.
source
share