javascript - Ajax get table value based on row -
i can first , last value row can`t second , third value of row. can me.
this code
=> html
<tr> <td>one</td> <td>two</td> <td>three</td> <td>four</td> <td><button class="btndelete">delete</button></td> </tr>
=> javascript
$(".btndelete").click(function (evt) { var cell=$(evt.target).closest("tr").children().first(); var cell2=$(evt.target).closest("tr").children().last(); var custid=cell.text(); var custid2=cell2.text(); alert(custid); alert(custid2); }
thanks .
i think it's easier values without jquery. using htmltablerowelement.cells dom property. array, not array.
$("#mytable").on('click','.btndelete',function(){ // current row var currentrow = $(this).closest("tr")[0]; var cells = currentrow.cells; var firstcell = cells[0].textcontent; var secondcell = cells[1].textcontent; //... //nthcell = cells[n-1].textcontent; console.log( firstcell ); console.log( secondcell ); });
if still want jquery, instead of .first()
, .last()
methods, use .eq()
method.
var rowcells = $(this).closest("tr").children(); var firstcell = rowcells.eq( 0 ).text(); var secondcell = rowcells.eq( 1 ).text();
Comments
Post a Comment