Uncaught Typeerror: Cannot read Property 'textContent' of null

Asked

Viewed 1,467 times

0

I cannot understand why this mistake is happening. Theoretically the error is due to not having this ID in html, but it exists... until I changed the name to check if something was misspelled...

<tr class="paciente">
                    <td class="info-nome">Paulo</td>
                    <td class="info-peso" id="peso-2">100</td>
                    <td class="info-altura" id="altura-2">2.00</td>
                    <

See the J...

    var tdpeso = document.getElementById("peso-2");
var tdaltura = document.getElementById("altura-2");

var peso = tdpeso.textContent;
var altura = tdaltura.textContent;


if (altura != 0) {
 var imc = peso / (altura * altura);

 console.log(imc);
 }else{
    console.log("Impossível executar pois altura é igual a zero");
 }
  • 1

    In your HTML you have < in the end, can you correct? maybe it’s </tr>? Question: where is Javascript on the page?

1 answer

1

Hello, this problem occurs due to the javascript import happening before the object is created, if you put the script import one line before the "" will be able to handle all the page objects quietly.

Browser other questions tagged

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