Take the 2-minute tour ×

I have a column with buttons in a table an i am using jQuery datatable plugin.
The buttons say "Remove" and the idea is that when you click on that button it deletes the current row in the table.

when I call fnDeleteRow it seems to work the first time but no any further time for that row so it looks like its not really deleting the row properly.

share|improve this question
Need more info. Do you use ajax to populate your datatable or are you converting a static html table? Also: why is the data no longer accurate? doesn't datatable move the tr (and corresponding id tags) on sort? –  r00fus Dec 18 '09 at 5:23
add comment

3 Answers

up vote 41 down vote accepted

Hmm. Try this:

var row = $(this).closest("tr").get(0);
share|improve this answer
+1 but I think closest would be a more appropriate selector than parents –  cobbal Dec 18 '09 at 6:58
i did switch it closest but after that it worked perfectly .. thanks –  leora Dec 18 '09 at 12:43
Why you added .get(0)? Thank you it works for me. –  shaahin Sep 14 '11 at 0:07
Thank goodness someone figured this one out!! –  Sydwell Jan 26 '12 at 20:01
On Target! Nice Answer! Thank you! –  Lucio Fonseca Sep 30 '13 at 1:12
add comment

Let's say you attached a function to be called when the user clicks on the button. The function would be something like this

function DeleteRow(event)
  //get the row of the cell that is clicked
  var $row = $(this).parents("tr").eq(0)
  //if you need the id you can get it as
  var rowid = $row.attr("id");
  //now you can call delete function on this row
share|improve this answer
this doesn't seem to work .. –  leora Dec 18 '09 at 5:00
add comment

from this page:

$('#example tbody td').click( function () {
    /* Get the position of the current data from the node */
    var aPos = oTable.fnGetPosition( this );

} );
share|improve this answer
but i am clicking on a button inside a table cell –  leora Dec 18 '09 at 4:33
add comment

Your Answer


