Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent click event from affecting parent jquery

I was to stop the event propagation 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 it doesn;t stop the event.Any suggestions ?

like image 640
andrei Avatar asked Oct 10 '22 19:10

andrei


1 Answers

stopPropagation has problems with live, from the jQuery stopPropagation docs -

Since the .live() method handles events once they have propagated to the top of the document, it is not possible to stop propagation of live events

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

like image 62
ipr101 Avatar answered Oct 19 '22 13:10

ipr101