Ticket #7131 (closed bug: invalid)
Multi Selector + Non Existnig Context + Live to bind event handlers = event is bound to all but first part of the multi selector
| Reported by: | nhaemhou | Owned by: | danheberden |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | selector | Version: | 1.4.2 |
| Keywords: | live, multi selector, context, event | Cc: | |
| Blocking: | Blocked by: |
Description
Found a pretty annoying bug. I was expecting that when the context doesn't exist (i.e. not found on the current page), that live would not attach the event handlers to the elements in a multi selector. Turns out that it does it as expected for the first part of the multi selector and then ignores the non existing context for the other parts (i.e. it attaches the event handler)
Example:
<div class="foobar">
<div class="a">AAA</div> <div class="b">BBB</div> <div class="c">CCC</div>
</div>
var ctx = $('.nonExistingClass'); $('.a, .b, .c', ctx).live('click', function(event) {
$(this).css('color','red');
});
If the context doesn't exist, live still attaches the event handler to .b and .c If you use bind instead, it works correctly and none of the parts of the multi selector get the event handler.
var ctx = $('.nonExistingClass'); $('.a, .b, .c', ctx).bind('click', function(event) {
$(this).css('color','red');
});
Change History
comment:1 Changed 3 years ago by addyosmani
- Priority changed from undecided to low
- Status changed from new to open
comment:3 Changed 2 years ago by danheberden
- Owner set to danheberden
- Status changed from open to assigned
- Milestone set to 1.next
Still present: http://jsfiddle.net/danheberden/Ezu5R/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I can confirm the behavior mentioned is experienced when using jQuery 1.4.2 or 1.4.3 RC2.
Flagging for a further review and possibly a patch if possible.