I have a page using jquery-ui-dialog. Each time the dialog opens, page contents load in using ajax. Then it binds some event using jquery "on()". When the dialog close, it will empty its content.
The question is, do I need to unbind the events on ".ajax-content" before $.empty()?
edit: concern 1. any possible degrade JS performance? if I empty() hundreds of nodes this way.
concern 2. would remove element also remove events from memory(or whatever execution/evaluation chain of jquery)?
I am not doing anything to them for now. If the dialog open/close for many times without page refresh, would it cause any problem?
Code look like this:
<div id="jquery-dialog" class="container">
<div class="ajax-content">
some buttons....
</div>
</div>
------after each ajax load------------
$(".ajax-content").on("click", ".button", function(event) {
//handles the click
});
------on dialog close------------
$("#jquery-dialog").empty();