Uncaught TypeError: Can not read property 'textContent' of null [closed]

0

I can not understand why this error is occurring. Theoretically the error is due to not having this ID in the html, but it does exist ... I even changed the name to check if something was spelled wrong ...

<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 Js ...

    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");
 }
    
asked by anonymous 16.05.2016 / 00:48

1 answer

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

    
01.09.2016 / 07:45