Ticket #7353 (closed bug: invalid)
Subsequent live event handlers can't be cancelled by returning false
| Reported by: | ashrewdmint | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.5 |
| Component: | unfiled | Version: | 1.4.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Documentation for live events says the following:
"To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this."
However, this does not seem to be the case. If you put the following HTML in a browser and click the link, the second live event is not blocked.
Maybe I am misreading the documentation?
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a').live('click', function(){
alert('hello, this is the first live event');
return false;
});
$('a').live('click', function(){
alert('this should not show up');
});
});
</script>
</head>
<body>
<a href="#">Click me</a>
</body>
</html>
Change History
comment:3 Changed 3 years ago by jitter
@ashrewdmint
You should use stopImmediatePropagation() for this not return false. The behavior in 1.4.2 was wrong that's why returning false worked but didn't anymore in 1.4.3.
Unfortunately calling stopImmediatePropagation() doesn't work in 1.4.3 for live handlers, but this has already been fixed and will work once 1.4.4 comes out.
Check also the comments on #7217 for more info on this.
Your test case with jQuery dev version
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

My bad, I didn't see the notice about jsFiddle before.
Here's my example on jsFiddle - http://jsfiddle.net/6krK5/