Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
Error javascript : Cannot read properties of null (reading 'innerHTML')

I'm just learning javascript, I'm using HTML DOM InnerHTML to display a list of data that I created and my code is based on OOP.

When it's on the page, it looks good. But when I move to another page, the error appears like this.

enter image description here

How can I get rid of the error. I want to display a list of data with innerHTML on another page but can't because of this error. This is my code :

let listCattle = [];

let nCattle = CattleDummy.length;
for (let i=0; i<nCattle; i++){
    s = CattleDummy[i];
    listCattle[i] = new Cattle();
    listCattle[i].addCattle(s._id, s.gender, s.cowType, s.age, s.weight, s.deseaseHistory, s.dateofDesease);    
}

tableCattle(listCattle);

function tableCattle(data){
    let table = document.getElementById('CattleTable')

    for(let i=0; i<data.length; i++){
        let row = `<tr>
                    <td>${data[i].getId()}</td>
                    <td>${data[i].getGender()}</td>
                    <td>${data[i].getSpecies()}</td>
                    <td>${data[i].getAge()}</td>
                    <td>${data[i].getWeight()}</td>
                    <td>${data[i].getDeseaseHist()}</td>
                    <td>${data[i].getHealthy()}</td>
                    <td>${data[i].getCondition()}</td>
                </tr>`
        table.innerHTML += row
    }
}

This is the code in monitoring page :

<div class="container" style="margin-top: 30px;">
        <table class="table">
            <thead>
            <tr>
                <td>ID</td>
                <td>Gender</td>
                <td>Species</td>
                <td>Age</td>
                <td>Weight</td>
                <td>Desease History</td>
                <td>Healthy</td>
                <td>Condition</td>
            </tr>
            </thead>
            <tbody class="table-group-divider" id="CattleTable">
            </tbody>
        </table>
    </div>

Edit : I know the problem is I've moved to another page where the 'CattleTable' id doesn't exist. Then how can I create another table on another page without displaying a CattleTable with innerHTML if the error is still there?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda