#6528 closed bug (worksforme)
Event still trigger after unbind at once
Reported by: | eagletsui | Owned by: | |
---|---|---|---|
Priority: | Milestone: | 1.4.3 | |
Component: | event | Version: | 1.4.2 |
Keywords: | Unbind | Cc: | |
Blocked by: | Blocking: |
Description
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript">
$(document).ready(function() {
$("#xyz").bind("click" , function() {
$("#xyz").unbind("click");
});
$("#xyz").bind("click" , function() {
alert("bug");
});
});
</script>
</head> <body>
<input type="button" id ="xyz" value = "click me"/>
</body>
</html>
In jquery 1.3.2 is no problem but 1.4.2 event still trigger.
Change History (4)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Okay, I did find the documentation here:
"If there are multiple handlers registered, they will always execute in the order in which they were bound."
So the remaining issue is with unbinding handlers inside a handler itself.
comment:3 Changed 13 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
And... calling e.stopImmediatePropagation() takes care of that.
comment:4 Changed 13 years ago by
Why this behavior doesn't equal 1.3.2? So many plug-in doesn't work.
Note that the "bug" alert appears only once.
I think there may be assumptions here that are not part of jQuery's documented behavior as far as I know:
Event handlers on an element are not guaranteed to be executed in the order they are attached.
Unbinding event handlers *inside* a handler for that event may not prevent a handler from being executed during that event's delivery.