0

I have a container that exists in my DOM .customers-container. Within that container, I am adding new "tr"s through ajax calls.

How can I apply event binding to those dynamically created elements. I am using below, but it's not working on the new elements:

 $('.customers-container').find('.glyphicon-remove').on('click', function(){
        $(this).closest('tr').hide();
     });

1 Answer 1

2

Delegate the event from .customers-container to .glyphicon-remove:

$('.customers-container').on('click', '.glyphicon-remove', function(){
    $(this).closest('tr').hide();
});

Note that the on method parameters have changed, now the first parameter click is the event name, the second parameter .glyphicon-remove are the elements that will receive the event binding from the .customers-container delegator, and the third function is the function to execute when the event fires.

Sign up to request clarification or add additional context in comments.

1 Comment

exactly what I needed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.