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

124
Vistas
"Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')" when the variable is clearly defined

Learning JavaScript and HTML coding through my Senior Highschool year. I cannot figure out why this error is occurring for the life of me. Can someone help me with this? Thank you so much!

Assignment for clarity: Using only JavaScript, add a list item to the Calendar that you need to complete from your list of chores.

Code:

<!DOCTYPE html>
<html>
<head>
    <style>
        td{
            height: 150px;
            width: 150px;
        }
    </style>
</head>
    <body>
        <table border = "1" id= "chores">
            <tr id = "days">
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
            </tr>
            <tr id = "tasks">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
        <script>
        
            var extraTask = document.createElement("li");
            extraTask.innerHTML = "Take dishes out of dishwasher";

            var extraTaskList = document.createElement("ul");
            extraTaskList.child = extraTask;

            var tasksRow = document.getElementById("tasks").children;
            tasksRow = tasksRow[3];
            
            var tableContainer = document.getElementById("chores");
            
            
            document.tasksRow.appendChild(extraTaskList);
            
        </script>
    </body>
</html>

The visual created by the code: https://i.stack.imgur.com/GEUZG.png

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Change document.tasksRow to tasksRow.

Also, use appendChild to append an element.

<!DOCTYPE html>
<html>
<head>
    <style>
        td{
            height: 150px;
            width: 150px;
        }
    </style>
</head>
    <body>
        <table border = "1" id= "chores">
            <tr id = "days">
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
            </tr>
            <tr id = "tasks">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
        <script>
        
            var extraTask = document.createElement("li");
            extraTask.innerHTML = "Take dishes out of dishwasher";

            var extraTaskList = document.createElement("ul");
            extraTaskList.appendChild(extraTask);

            var tasksRow = document.getElementById("tasks").children;
            tasksRow = tasksRow[3];
            
            var tableContainer = document.getElementById("chores");
            
            
            tasksRow.appendChild(extraTaskList);
            
        </script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
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