so I'll be short: jquery .off()
doesn't disable a listen I've set with .on
.
html:
<span id=myspan>lol</span>
<button id=b1>jquery On</button>
<button id=b2>jquery Off</button>
js:
$(#b1).on(click, add);
$(#b2).on(click, del);
function add() {
$(#myspan).on(click, function(e) {
var a = 1;
testfunc(a, e);
});
}
function del() {
$(#myspan).off(click, testfunc);
}
function testfunc(num, event) {
alert(num);
}
So first we add to myspan the testfunc()
by clicking the jquery On button. After we do that, if we click on the span, we get an alert. Next, we click the jquery off button. That is supposed to remove the listener but it doesn't. Even after that, when we click on myspan testfunc
is still attached.
Why? And how can I remove it ?