Disable click event affect parent jquery

I had to stop the propagation of the event from the child to the parent, I have a bunch of li tags containing a .

 $('li a[rel=close]').live('click', function(e){ e.stopPropagation(); e.preventDefault(); }) 

But this does not stop the event. All offers?

+4
source share
3 answers

stopPropagation has problems with live , from jQuery stopPropagation docs -

Since the .live () method handles events, as soon as they propagate to the top of the document, it is impossible to stop the distribution of live events

As Rob W said, your code will work fine with bind , here's the demo - http://jsfiddle.net/TmKyT/

+2
source

Use .bind instead of .live . The live event fires at the end of the distribution tree. live more useful than bind if you also want to bind an event listener for items that are created later.

+1
source

Maybe try using a delegate?

 $('ul.parent').delegate('li a[rel=close]', 'click', function( event ) { } 
0
source

All Articles