samedi 23 janvier 2021

variable (element).style is undefined

    <textarea id="textarea" rows="10" cols="50" maxlength="10"></textarea>
    <span id="counter">10</span>
    <script>
        let textArea=document.getElementById('textarea'),
        counter=document.getElementById('counter'),
        number=counter.innerHTML;
        textArea.oninput=function(){
        counter.innerHTML=number-textArea.value.length;
        if(number==0){
            number.style.color="red";//number.style is undefined
        }else{
            number.style.color="black";
        }
    }
    </script>

why it says variable (element).style is undefined? I tried .style.color="red"; on a different code & it works!

Aucun commentaire:

Enregistrer un commentaire