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

108
Views
How to get the a child's parent's ID in JavaScript

I need to get the child's parent's ID

Heres what I Mean:

<div class="task" id="TheParent">
            <img class="task-img" src="./index.png" />
            <div class="Text-Container">
                <p class="task-maintitle">Sample Task</p>
                <p class="task-desc">Sample Desc</p>
            </div>


            <input type="checkbox" class="Check" id="check" onclick="Remove(this.id)" />
            <!--Need this element's parent's id-->  

        </div>

I need to get it with this specifically because there are going to be many elements which are just duplicates.

Is there any way to get the parent's id?

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

0

You can get it with this.parentNode

I added this.parentNode.id for the demo purpose

function getParent(parenId) {
   console.log(parenId)
}
<div id="parent-div">
   <button onclick="getParent(this.parentNode.id)">
     Test
   </button>
</div>

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!