jquery - How to get cell value to confirm on javascript? -


this question has answer here:

i have html code , want when click delete delete current row, show confirm " want delete [name]?" so, how can name value confirm when click delete using jquery?

<table id="tblinfo">      <thead>     <tr>         <th>#</th>         <th>name</th>         <th>birthday</th>         <th></th>     </tr>     </thead>      <tbody>     <tr>         <td>1</td>         <td>name1</td>         <td>01/01/1990</td>         <td>             <a href="#" class="btnview" >view</a>             <a href="#" class="btndelete">delete</a>         </td>     </tr>     <tr>         <td>2</td>         <td>name2</td>         <td>01/01/1990</td>         <td>             <a href="#" class="btnview">view</a>             <a href="#" class="btndelete">delete</a>         </td>     </tr>     </tbody>      <tfoot>     <tr>         <td></td>         <td><input type="text" name="" value="" size="25" /></td>         <td><input type="text" name="" value="" size="25" /></td>         <td>             <a href="#" class="btnadd">add</a>         </td>     </tr>     </tfoot> </table> 

demo: http://jsfiddle.net/1qda1jpx/1/

$(document).ready(function() {     $("#tblinfo").on("click", ".btndelete", function() {         var $this = $(this);         var name = $this.closest("tr").find("td:nth-child(2)").text(); // gets name of row         if (confirm("do want delete" + name + "?"))         { $this.closest('tr').remove(); } // upon confirmation, remove row     }); }); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -