[英]How do I make it so that if I click an <a> element it goes to the link, but it doesn't trigger the .click() event of its parent element?
I want to be able to click on a particular <a>
and activate the link out, but not the parent's click. 我希望能够点击特定的
<a>
并激活链接,但不能激活父亲的点击。
preventDefault()
doesn't work because then it won't link out. preventDefault()
不起作用,因为它不会链接出来。
You should use e.stopPropagation()
to stop the event from bubbling. 您应该使用
e.stopPropagation()
来阻止事件冒泡。
Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
防止事件冒泡DOM树,防止任何父处理程序被通知事件。
~from jQuery docs .stopPropagation 〜来自jQuery docs .stopPropagation
You have to use stopPropagation
instead of preventDefault
您必须使用
stopPropagation
而不是preventDefault
$('a').click(event){
event.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.