jquery - Finding which table row has the selected class so that it can be deleted -
i have this:
$("tbody").on("click", "tr", function(e) { $(this) .toggleclass("selected") .siblings(".selected") .removeclass("selected"); });
which allows me select specific row , assign "selected" class. user has option click delete button on bottom of table delete row he's selected. thinking of, when user clicks delete button, iterate through of table rows , delete 1 selected tag, i'm not sure how this. there better way or can explain how done?
since didn't provide html, i'm creating own table.
css background color see table row 'selected' class
<style> .selected{ background-color:#dddddd; } </style>
generic table , button
<table> <tbody> <tr> <td>sunday</td> <td>01</td> </tr> <tr> <td>monday</td> <td>02</td> </tr> <tr> <td>tuesday</td> <td>03</td> </tr> </tbody> </table> <button id="deleterow">delete row</button>
jquery add class , remove table rows
$(function() { $(document).off('click', 'tbody tr').on('click', 'tbody tr', function() { var $this = $(this); if ($this.hasclass('selected')) { $this.removeclass('selected'); } else { $this.addclass('selected'); } }); $(document).off('click', '#deleterow').on('click', '#deleterow', function() { $('tbody tr.selected').remove(); }); });
Comments
Post a Comment