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

196
Views
Target closest Table Row when button inside of TD is clicked jQuery

So. I have this table:

<table>
    <tr>
        <td>Element1</td>
        <td>Element1</td>
        <td>Element1</td>
        <td><a id="btn" href=#">Accept</a></td>
    </tr>
    <tr>
        <td>Element2</td>
        <td>Element2</td>
        <td>Element2</td>
        <td><a id="btn" href=#">Accept</a></td>
    </tr>
</table>

What I want to do is: Button gets clicked, it gets hidden and the respective <tr> gets border: 1px solid black;.

I'm kinda new to jQuery and can't figure out how to select the 2nd parent of an element. Any help would be appreciated

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

0

  1. your buttons are using the same id value. you have to use class
  2. Also you don't need to use jQuery. please follow this code

const btns = document.querySelectorAll('.id');
btns.forEach((btn) => {
  btn.addEventListener('click', (e) => {
    e.preventDefault();
    e.target.closest('tr').style.cssText = "border:1px solid black";
    e.target.remove();
  })
});
table {
  border-collapse: collapse
}
<table>
    <tr>
        <td>Element1</td>
        <td>Element1</td>
        <td>Element1</td>
        <td><a class="id" href=#">Accept</a></td>
    </tr>
    <tr>
        <td>Element2</td>
        <td>Element2</td>
        <td>Element2</td>
        <td><a class="id" href=#">Accept</a></td>
    </tr>
</table>

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!