var refreshId = setInterval(function() { var properID = CheckReload(); if (properID > 0) { clearInterval(refreshId); //this stops the setInterval } }, 10000);