Change the following code
$('.toggleBtn').click(function(e) {
to the following
$("body").on("click", ".toggleBtn", function(e){
I think this is what you needed.
Here I added the event to body
since I don't know your HTML structure. You should attach the .on
to the datagridview or its parent, so that the event doesn't have to bubble too much.
Update:
It is not a good idea to append events on each row, especially when there are too many rows. It will make the script too heavy. So it is recommended to use .on
in these cases. In older versions of jQuery you may have to use .live
instead of .on
.