I have a table and buttons and all buttons are getting generated with a loop.
<button type="button" class="btn btn-danger btn-sm remove-connetion" name="button">
<i class="fa fa-trash"></i>
</button>
I want to find which button I click and then change its class.
now in my jquery script
$( document ).on( 'click', '.remove-connetion', function (e) {
e.preventDefault();
$('td').find('.fa fa-trash').closest('button').removeClass('btn-danger');
$('td').find('.fa fa-trash').closest('button').addClass('btn-secondary');
});
it’s not changing class.
Thanks for all help
2
Answers
Use
this
instead inside the callback to get the current clicked button:You can do it like this: