How to prevent the event from triggering by default, but still let the event bubble

Using jQuery: with the following code, I would like the href url (in this case, the hash '#') to start when clicked, but still allows the click event to continue to expand the chain. How can this be achieved?

<div> <a href="#">Test</a> </div> $('a').click(function(e){ // stop a.click firing but allow click event to continue bubbling? }); 
+7
source share
3 answers
 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

e.preventDefault() will not prevent bubbling, e.stopPropagation() or return false (stop both).

+8
source

You can do:

 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

fiddle here http://jsfiddle.net/tU53v/

0
source

try it.

 $('a').click(function(e){ e.preventDefault(); // stop a.click firing but allow click event to continue bubbling? }); 

here you can find the difference between return false and e.preventDefault();

0
source

All Articles