Having a code like this, I’m wondering if I ran this function a second time, which scenario will happen:
- When emptying the #deals tag, all
btninside will get wiped as well despite the event on them and life is good. - I have to unsubscribe from those
btnfirst, otherwise emptying the#dealstag leads to a memory leak? - List item
Code:
function test(){
var row = $(this).closest('tr');
$(row).find('#deals').empty();
$(result).find('#tab li a').each(function() {
var btn = $('<a/>', {class: 'btn', href: '#'});
$(row).find('#deals').append(btn);
btn.click(function(event){
event.preventDefault();
...
});
});
}
You don’t have to unsuscribe :
(from the documentation)