I had code like this:
$('.remove-group').click(function () { $(this).closest('tr').remove(); }); This worked fine until I needed to use delegated event handler to capture clicks for elements that will be added to the page in the future.
$(document).on('click', '.remove-group', function () { $(this).closest('tr').remove(); }); This no longer works because the this keyword does not refer to the originating element.
Any ideas?
Update
It would seem that in my efforts to simplify the code for my question I actually made it work. I was actually passing in a wrapped set that was assigned to a variable instead of the string selector.
var $removeGroup = $('.remove-group'); $(document).on('click', $removeGroup, function () { $(this).closest('tr').remove(); }); That doesn't seem to work when I do it that way.
thisshould still refer to the.remove-groupelement though. What are you expecting it to refer to, and what do you think it is referring to? (might help to include some html)