我正在尝试添加一个点击事件到一个类为 parent 的 div
元素上。该元素中有一个类为 child 的 div
元素,它也有自己的点击事件。
如何才能禁用父元素的点击事件以便执行子元素自己的函数?
我尝试使用 pointer-event:none;
但似乎它并没有起作用。我已经创建了一个 jsfiddle,以便更好地理解:
https://jsfiddle.net/arq1epbs/
$(document).on('click', '.parent', function() {
var url = $(this).attr("data-url")
document.location.href = url
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="parent" data-url="www.google.com">
Im the parent
<div class="child">
im the child and I don't want to go to Google
</div>
</div>
非常感谢您提前提供的所有帮助!