我有一个在悬停父 div 时运行的函数,它应该在悬停子 div 时停止工作,因为还有另一个函数。
<div class="parent">
//Here the function should work
<div class="child">Text </div> // here it should stop working
//Here the function should work
</div>
我正在调整它以在父 div 上工作
if ($('.parent').is(':hover')) {做东西}
我对这样的东西很感兴趣:
if ($('.parent').is(':hover') AND NOT $('.child').is(':hover')) { do stuff }.
我怎样才能做到这一点?
谢谢!
最佳答案
像下面那样使用event.stopPropagation()
$('.parent').hover(function(){
alert('parent');
})
$('.child').hover(function(e){
e.stopPropagation();
alert('child');
})
关于javascript - 将鼠标悬停在元素上时使功能停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25510281/