Ticket #6784 (closed bug: wontfix)
Different behaviour with binding multi eventhandlers pointing to the same function(s) occurs in 1.4.1 and 1.4.2
| Reported by: | gillis | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | event | Version: | 1.4.2 |
| Keywords: | bind,events | Cc: | |
| Blocking: | Blocked by: |
Description
When binding for example 2 event handlers to an element with both bindings pointing to the same function, there is a different behaviour in 1.4.1 and 1.4.2
in 1.4.1 it seems that the second bind is seen as a duplicated and won't be attached to the dom element. This is exactly what i want. in 1.4.2 both bind are working.
<div id="test" style="height:200px; height:200px; background-color:red;"> </div>
<script>
function handleClick() { console.log('click'); } jQuery('#test').bind('click',handleClick);
jQuery('#test').bind('click',handleClick);
</script>
clicking on it in 1.4.2 results in two logs, in 1.4.1 one.
Change History
comment:2 Changed 3 years ago by addyosmani
- Priority set to undecided
- Status changed from new to closed
- Resolution set to wontfix
Please refer to the official jQuery documentation regarding the updates made for the 1.4.2 release with respect to .bind().
URL:http://api.jquery.com/bind/
The below is an example of the behavior you will experience when defining duplicate event handlers, whether using shorthand or the complete write-up of the bind() code needed.
"As of jQuery 1.4.2 duplicate event handlers can be bound to an element instead of being discarded. For example:
function test(){ alert("Hello"); } $("button").click( test ); $("button").click( test );
The above will generate two alerts when the button is clicked."
Closing ticket as the behavior experienced is something previously agreed upon as being a part of the 1.4.2 jQuery release.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
