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

160
Vistas
How to change parent element by the class name of the child element

When i clickk on the button with the Id "add" it will append a div with the class "note" to a space i named "notespace", inside the note it will be a div element with the class "expand" which will function as a button.

My goal is to be able to change the style attributes of the parent "note" element by clicking on the "expand" div inside of it.

I tried to change the size of the note to 3000px, but i got an error message, this one:

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

Any ideas on how i can fix this?

<script>

var add = document.getElementById("add");

add.addEventListener("click", function(){
    var textValue = text.value;
    var p = document.createElement("p");
    p.innerHTML = "<div class='note'>" + textValue + "<br/><br/><div class='expand'> Expand </div></div>";
    notespace.appendChild(p);
    text.value = "";


        for( var i = 0; i < expand.length; i++){
            expand[i].addEventListener("click", function(){
                notes[i].style.size = "3000px";
            })
    
        }    

  

    
 

})

 </script>
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