子操作不会触发父jquery

时间:2011-08-07 21:37:14

标签: javascript jquery html

我在父div中有一对<a>,它会在点击时执行特定操作。如何才能使用户点击每个<a href="xxxx">时,用户只会链接到其他页面并且不会触发父函数?

1 个答案:

答案 0 :(得分:3)

阻止click事件冒泡到父母,如下所示:

$("a").click(function(e) {
    e.stopPropagation();
});

请参阅event.stopPropagation

Demo.