Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda