Well, since you're using a delegated event attached to .container
, your event listener will NOT be removed.
Like documentation says:
Event delegation allows us to attach a single event listener, to a
parent element, that will fire for all descendants matching a
selector, whether those descendants exist now or are added in the
future.
This means that whenever a click event is triggered inside .container
, will always execute a query to check if the clicked element is #testDiv
This can't be defined memory leak, because it's exactly how is supposed to work event delegation. Read this post where is explained performance differences between event delegation and direct binding.
Anyway, if you don't need that listener anymore you can either:
- call .off() function to manually remove the listener before removing the element
- or just don't use event delegation if you don't really need, but direct binding