jquery - How to change enable to disable in Td? -
i have question. have table data
as
<table> <tr> <td>enabled</td> <td><button class="js-enabled">desabled</button></td> </tr> <tr> <td>desabled</td> <td><button class="js-enabled">enabled</button></td> </tr> <tr> <td>enabled</td> <td><button class="js-enabled">desabled</button></td> </tr> <tr> <td>desabled</td> <td><button class="js-enabled">enabled</button></td> </tr> <tr> <td>enabled</td> <td><button class="js-enabled">desabled</button></td> </tr> <tr> <td>desabled</td> <td><button class="js-enabled">enabled</button></td> </tr> </table>
and used jquery function
$('.js-enabled').click(function(){ $(this).replacewith('<button class="btn btn-success">active</button>'); });
now want to
- if click enable button change enabled disabled
left
,right
both side
for sake of answer i'll use code, let know, it's spelled 'disabled'.
$('.js-enabled').click(function(){ var button = $(this); var label = $(this).parent().prev('td'); button.text() == 'desabled' ? button.text('enabled') : button.text('desabled'); label.text() == 'desabled' ? label.text('enabled') : label.text('desabled'); });
Comments
Post a Comment