2016-01-16 61 views
0

我有一个div,在我的简单页面上通过jQuery的类选择器检索。我想那么鼠标事件侦听器附加到这个div ...鼠标悬停事件没有被触发的jQuery类选择元素

<body> 
<div class="stuffBox"> 
    <h1> 
    stuff 
    </h1> 
</div> 
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
<script> 
    (function(){ 
     $(".stuffBox").mouseover(function() { 
    alert("Here is some stuff"); 
}); 
}) 

</script> 
</body> 

这里是小提琴https://jsfiddle.net/jehanjaleel/xqtp2r3q/

眼下鼠标悬停在不触发,任何想法,为什么?

我想重新打开它,因为它在jsfiddle中工作,但不在实际的html页面上。

+4

打开浏览器的开发者工具。阅读它给你的错误信息。 **未捕获ReferenceError:$未定义** – Quentin

+0

@Quentin和Josh,当我在独立的html页面中尝试此代码时(虽然它在js小提琴中工作),仍然存在此问题。您能否重新打开并复制并粘贴该代码并尝试? – AbuMariam

+0

现在你已经有了完全不同的问题。这应该是一个新问题,而不是现有编辑。 – Quentin

回答

0
<body> 
<div class="stuffBox"> 
    <h1> 
    stuff 
    </h1> 
</div> 
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
<script> 
(function(){ 
$(".stuffBox").mouseover(function() { 
alert("Here is some stuff"); 
}); 
}) 

</script> 
</body> 
相关问题