Skip to main content

Bug Tracker

Side navigation

#8521 closed bug (worksforme)

Opened March 14, 2011 10:21AM UTC

Closed March 30, 2011 05:13PM UTC

Last modified March 31, 2011 08:46AM UTC

There is funny bahaviour with mutiple bindings 'live' and 'return false'.

Reported by: MICKtheBIG Owned by: MICKtheBIG
Priority: undecided Milestone: 1.next
Component: event Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

I've expierienced this issue with more than one event handler on links in Firefox 3.6.3.

Try the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de" >
    <head>
        <title>Live-Binding-Test</title>
		
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

        
        <script type="text/javascript" src="js/jquery.js"></script>

        <script type="text/javascript">
        	$(document).ready(function() {
        		
        	    $(".j_controlButton").click(function(){
        		    return false;
        		});
        	    
        		$(".j_controlButton").live("click", function(){alert("click 'live' binding callback executed")});
        		$(".j_controlButton").bind("click", function(){alert("click 'bind' binding callback executed")});
        		
        		
        		$("body").append('<a href="#" class="j_controlButton">Dynamic DOM-Link</a>');
        		
            });
        </script>
    </head>
    <body>
        <a href="#" class="j_controlButton">Static DOM-Link</a> <br /> <br />
    </body>
</html>

With "return false;" at line 16 only the event with "bind" is triggered for the "Static DOM-Link".

Then comment out line 16 (return false;) After this you'll see, that the live binding is also triggered for the "Static DOM-Link". This is from my point of view a funny behaviour. Eigther the "bind"-Binding shouldn't work all the time for the "Static DOM-Link" or the live-binding should work with or without "return false;". From my point of view the live-binding should work with and without "return false;" from line 16.

I hope you understand this issue and it's not a duplicated issue....

Attachments (0)
Change History (6)

Changed March 14, 2011 02:57PM UTC by rwaldron comment:1

component: unfiledevent
owner: → MICKtheBIG
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket!

Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

Changed March 14, 2011 03:09PM UTC by MICKtheBIG comment:2

status: pendingnew

Live-Binding should work on "Static DOM-Link" but does not:

http://jsfiddle.net/5JtSb/

Live-Binding now works on "Static DOM-Link" with removing return false:

http://jsfiddle.net/Q7uyt/1/

The thing is, that "bind" always works on the "Static DOM-Link" even with return false. The live binding only works when return false ist removed

Changed March 30, 2011 05:13PM UTC by dmethvin comment:3

resolution: → worksforme
status: newclosed

That is correct behavior. When you return false from an event handler directly bound to the element, it prevents the event from bubbling to the document where the .live() would see it.

Changed March 30, 2011 05:57PM UTC by ajpiano comment:4

MICKtheBIG replied:

"Yes, I know that it does this ("it prevents the event from bubbling to the document") but why is it then working with "bind"? Then you actually said that "bind" isn't working correctly. But it would have horrible side effects if you would change that. I still think that "bind" and "live" is behaving inconsistency in this case."

but i accidentally deleted it because the comment was showing up twice. So here it is again. ^^

Changed March 30, 2011 08:51PM UTC by dmethvin comment:5

There are TWO event handlers directly bound to the element. A return false does a event.preventDefault() and an event.stopPropagation() to stop the event from bubbling *up* the DOM tree. However, it does not event.stopImmediatePropagation() which would prevent further event handlers *at the same level* from executing.

Changed March 31, 2011 08:46AM UTC by MICKtheBIG comment:6

Alright, I was just wondering. I can deal with this. No problem. I just thought I might inform you about this behaviour because I thought it wasn't supposed to behave like it does at the moment. So everything is nice. I just couldn't find a hint for this in the API docs. I should have inspected this issue in the jQuery-Core but I didn't....