Only last binded event can be really unbind ?
Hi jQuery team!
I've been working of markItUp! and i found a strange behavior on
unbind function. It seems that only last binded event can be really
unbind forever.
Code:
<script src="jquery.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#on").click(function() {
$
("#textarea").click(aClick).keydown(aKeyIsDown).keyup(aKeyIsUp).css("border",
"1px solid red");
});
$("#off").click(function() {
$("#textarea").unbind();
});
function aKeyIsUp() {
console.log("up");
}
function aKeyIsDow() {
console.log("down");
}
function aClick() {
console.log("click");
}
});
</script>
<a id="on" href="#">On</a> | <a id="off" href="#">Off</a>
<textarea id="textarea"></textarea>
Results :
Click on 'On' link
Click and press a key in the textarea.
Each event is trigger once : ok.
Click on 'Off'
Click and press a key in the textarea.
None of the events is trigger : ok.
Click on 'On' again
Click and press a key in the textarea.
First and second events are trigger 2 times, last one 1 time :
Error!.
Click on 'On' / 'Off' 5 times then 'On'
Click and press a key in the textarea.
First and second events are trigger 5 times, last one 1 time :
Error!.
Is there a bug or something i don't understand ?
Thanks.
Jay