Answered by:
clicking on last table column

Question
-
User-952877843 posted
how can i click on last table column to show alert by using jquery
Saturday, August 18, 2018 6:06 AM
Answers
-
User-369506445 posted
I created a sample <g class="gr_ gr_4 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="4" data-gr-id="4">wit h</g> <g class="gr_ gr_7 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="7" data-gr-id="7"><g class="gr_ gr_6 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="6" data-gr-id="6">datatable</g> ,</g> please try
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script> <script> $(document).ready(function () { $('#example').DataTable(); $("#example tbody").on("click", "td:last-child", function () { alert("ok") }); }); </script> <table id="example" class="table table-striped table-bordered" style="width:100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td> <td>Edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>$320,800</td> </tr> <tr> <td>Garrett Winters</td> <td>Accountant</td> <td>Tokyo</td> <td>63</td> <td>2011/07/25</td> <td>$170,750</td> </tr> </tbody> </table>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 18, 2018 8:17 AM -
User-369506445 posted
hi
you can try below
<script> $(document).ready(function () { $('#example').DataTable(); $("#example tbody").on("click", "td:last-child", function () { alert($(this).text()) }); }); </script>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 21, 2018 12:10 PM
All replies
-
User-369506445 posted
hi
please try below code
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $(function () { $('td:last-child').click(function (event) { alert('click'); }); }) </script> <table id="myTable"> <tr> <th>Col1</th> <th>Col2</th> <th>Col3</th> </tr> <tr> <td>val 1</td> <td>val 2</td> <td>val 3</td> </tr> <tr> <td>val 1</td> <td>val 2</td> <td>val 3</td> </tr> </table>
Saturday, August 18, 2018 6:24 AM -
User-952877843 posted
not working on my side i have a datatable
Saturday, August 18, 2018 6:27 AM -
User-369506445 posted
I put a Demo in the last post, it work, please see it.
also, put your code here
Saturday, August 18, 2018 6:31 AM -
User-369506445 posted
I created a sample <g class="gr_ gr_4 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="4" data-gr-id="4">wit h</g> <g class="gr_ gr_7 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="7" data-gr-id="7"><g class="gr_ gr_6 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="6" data-gr-id="6">datatable</g> ,</g> please try
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> <link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" /> <script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script> <script> $(document).ready(function () { $('#example').DataTable(); $("#example tbody").on("click", "td:last-child", function () { alert("ok") }); }); </script> <table id="example" class="table table-striped table-bordered" style="width:100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td> <td>Edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>$320,800</td> </tr> <tr> <td>Garrett Winters</td> <td>Accountant</td> <td>Tokyo</td> <td>63</td> <td>2011/07/25</td> <td>$170,750</td> </tr> </tbody> </table>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, August 18, 2018 8:17 AM -
User-952877843 posted
if i want by clicking on last td show me the value on each row how can i do it?
Tuesday, August 21, 2018 11:57 AM -
User-369506445 posted
hi
you can try below
<script> $(document).ready(function () { $('#example').DataTable(); $("#example tbody").on("click", "td:last-child", function () { alert($(this).text()) }); }); </script>
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, August 21, 2018 12:10 PM -
User-952877843 posted
if i want to get the value of first column also with the value of last column how can i do it?
Friday, August 24, 2018 7:33 AM