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

148
Views
Reach the parent element from the child

i have some elements that contain a couple of elements. I want when I click on the child element, the parent of the element disappears with all its nested elements (nested_parent and the nested_parent1 and the child) .

.parent{
    margin-top: 10px;
    width: 125px;
    height: 125px;
    background-color: red;
    display: flex;
    justify-content: center;
    align-items: center;
}
.nested_parent {
    width: 100px;
    height: 100px;
    background-color: aqua;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
}
.nested_parent1 {
    width: 75px;
    height: 75px;
    background-color: blueviolet;
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
}
.child {
    width: 50px;
    height: 50px;
    background-color: beige;
    cursor: pointer;
}
<div class="parent">
        <span class="nested_parent">
            <span class="nested_parent1">
                <i class="child"></i>
            </span>
        </span>
    </div>
    <div class="parent">
        <span class="nested_parent">
            <span class="nested_parent1">
                <i class="child"></i>
            </span>
        </span>
    </div>
    <div class="parent">
        <span class="nested_parent">
            <span class="nested_parent1">
                <i class="child"></i>
            </span>
        </span>
    </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Add a click handler to the children:

$('i.child').click(function(){
  $(this).parent().parent().hide()
})

When you click a child, it will cause its grandparent to hide (.nested_parent), which automatically hides its descendants (.nested_parent1 and .child).

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