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

197
Views
Get Parent div on button click

I have the following html:

<div id = "CompOne">
    <div id="btns">
        <input type="button" value="Add" class="cartbtn" onclick="SetSubmitBundleValue(this)">
    </div>
</div>

<div id = "CompTwo">
    <div id="btns">
        <input type="button" value="Add" class="cartbtn" onclick="SetSubmitBundleValue(this)">
    </div>
</div>

And I want to get value of the parent div CompTwo/ CompOne on their button click. Is it possible to retrieve this value from the object passed through the 'this' keyword? Kindly help

function SetSubmitBundleValue(obj)
{
    //Get Parent div
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use parent() method:

$('.cartbtn').on('click', function(){
 var parent_id = $(this).parent().parent().attr('id');
 console.log(parent_id);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id = "CompOne">
    <div id="btns">
        <input type="button" value="Add" class="cartbtn">
    </div>
</div>

<div id = "CompTwo">
    <div id="btns">
        <input type="button" value="Add" class="cartbtn">
    </div>
</div>

about 4 years ago · Santiago Trujillo 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!