Home > Software engineering >  How can i run a function if the value of a html is under a certain number
How can i run a function if the value of a html is under a certain number

Time:11-14

Im trying to create a script that will run a function if a value is above 0 and refresh the page if its under 0 using html. Im trying to run this script in chrome dev tools

here is my script so far. var is erroring.


function Above()
    var text = document.querySelector("#belowcard > h3:nth-child(2)");
    if (text == &#60) {
     location.reload();
    }
    else{
     PowerP();
    }
}

     
    

CodePudding user response:

To execute the function only once, use the setTimeout() method instead.

To clear an interval, use the id returned from setInterval():

myInterval = setInterval(function, milliseconds);

Then you can to stop the execution by calling clearInterval():

clearInterval(myInterval);

CodePudding user response:

const numberEl=document.getElementByYouSelector;
function reloadPage(){
const value=Number(numberEl.textContent);
if(value<0) window.location.reload();
}
  • Related