简体   繁体   中英

setTimeout not working to dissapear <p> tag

I'm a fair rookie to JS and I'm working on a project that needs me to make a non-functioning validation system. Here is the code i have at the moment:

I don't know why the setTimeout is not working, I checked on other posts as well but had no understanding. It seems my function dissapearText is not being recognised since i have a console.log as a test to see if it runs, but it's not appearing in the devtools console. Any simple solution would do.

Thanks, Arthur

{
let validation = document.querySelector('.type__style');
let validation2 = document.getElementById("label__text");

const init = () =>{
    const $button = document.getElementById('send__button');
    $button.onclick = () => {
        revealText();
        setTimeout(dissapearText,4000);
    }

    const revealText = () => {
        if (validation.value === ""){
            validation.focus();
            window.alert("Please enter your name.");
            return false;
        }else if(validation2.value === ""){
            validation2.focus();
            window.alert("Please fill in commentary.");
            return false;
        }else{
            document.querySelector('.feedback').style.opacity = 1;
            return true;
        }

    }

    const dissapearText = () => {
        if (revealText === true){
            console.log("sup");
            document.querySelector('.feedback').style.opacity = 0;
        }
    }

}
init();

}

The issue is

if (revealText === true)

revealText is a function which returns a boolean, you need to change this to

if (revealText() === true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM