Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
No se pueden leer las propiedades de undefined (leyendo 'classList') mientras se ha declarado la clase

Tengo un problema cuando trato de agregar un nombre de clase al div principal cuando el hijo tiene un nombre de clase de 'full-width'

Se utiliza el siguiente código y marcado

JS

 const child = document.getElementsByClassName('full-width'); child.parentElement.classList.add('full-width-container');

HTML

 <div class="wp-container-10 wp-block-columns"> <div class="wp-container-9 wp-block-column full-width has-green-background-color has-background"> <!-- content --> </div> </div>

Sin embargo, recibo un error en mi consola que dice

Uncaught TypeError: Cannot read properties of undefined (reading 'classList')

Al buscar este error, ocurre principalmente al intentar acceder a la propiedad classList en un valor nulo. Sin embargo, esto no es cierto cuando registro child .

console.log(child) devuelve

 HTMLCollection [] 0: div.wp-container-9.wp-block-column.full-width.has-green-background-color.has-background length: 1 [[Prototype]]: HTMLCollection

Además, el JavaScript se carga al final de la página después del HTML que tiene el nombre de la clase.

Realmente no entiendo por qué sigo recibiendo este error y por qué este código no funciona. Cualquier ayuda es muy apreciada.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!