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

157
Views
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
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!