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

131
Views
How to display data in its row table?

let's say I have 5 rows of data, is there a way where I can display the data on its row? how? in my code, when I hit the button on row 5 the result displays in data column.

<table>
<th>action</th><th>data</th>
<tr>
 <td>
   <button class="getdata" type="button" data-id="1">
 </td>
 <td>
   <i class="data"></i>
 </td>
</tr>
<tr>
 <td>
   <button class="getdata" type="button" data-id="2">
 </td>
 <td>
   <i class="data"></i>
 </td>
</tr>
<tr>
 <td>
   <button class="getdata" type="button" data-id="3">
 </td>
 <td>
   <i class="data"></i>
 </td>
</tr>....
</table>
$('.getdata').click(function(){
  var id = $(this).attr('data-id');
  $.ajax({
    url: 'log.php',
    method: 'GET',
    data:{id:id},
    success:function(){
      $('.data').html(id)
     }
    })
  })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In your AJAX success / done handler, traverse up from the current button to a sensible parent (<tr>) then down to the .data element

$('.getdata[data-id]').on("click", function() {
  const btn = $(this)
  $.get("log.php", { id: btn.data("id") }).done(data => {
    btn.closest("tr").find(".data").html(id) // or data ¯\_(ツ)_/¯
  })
})

See .closest()


Did you know, you might not need jQuery

// using event delegation at the <table> level
document.querySelector("table").addEventListener("click", async e => {
  const btn = e.target.closest("button.getdata[data-id]")
  if (btn) { // the click came from a button
    const id = btn.dataset.id
    const params = new URLSearchParams({ id })
    const res = await fetch(`log.php?${params}`)
    const data = await res.text()
    if (res.ok) {
      btn.closest("tr").querySelector(".data").innerHTML = id // or data
    } else {
      console.error(res.status, data})
    }
  }
})
over 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!