Pq o res.innerHTML does not update to "All right so far"

Asked

Viewed 33 times

-2

<body>
    <h1>Soma 3 num 5 alunos</h1>
    
    <section>
        <p>Qual o nome do aluno: <input type="text" name="nome" id="nome"></p>
        <p>1º nota: <input type="number" name="n1" id="n1"></p>
        <p>2º nota: <input type="number" name="n2" id="n2"></p>
        <p>3º nota: <input type="number" name="n3" id="n3"></p>
        <br> <input type="button" value="Enviar" onclick="enviar()">
    </section>
    <br>
    <section>
        <select name="lista" id="lista" size="8"></select>
        <br><br><input type="button" value="Finalizar">
    </section>
    <br>
    <section>
        <div id ='res'> Resposta...</div>
    </section>

    <br><footer>&copy GenesisHenriques</footer>
    <script>
        let nome = document.querySelector('input#nome').value;
        let n1 = document.getElementById('n1').value;
        let n2 = document.getElementById('n2').value;
        let n3 = document.getElementById('n3').value;
        let res = document.getElementById('div#res');

        function enviar(){
        res.innerHTML = `Certo até aqui`
        }
    </script>
</body>

1 answer

2

You are wearing this:

let res = document.getElementById('div#res');

That is wrong!

The value div#res is a selector. This would work properly if you were using the function document.querySelector.

To use the function getElementById, you must pass only the name of id of the element.

 let res = document.getElementById('res');

TIP: It is always important to look at the browser console, to know if there is an error being displayed. Just press F12. This helps a lot to check what is wrong, rather than looking for the solution randomly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.