jQuery mouseenter事件未执行

彼得·贝卡(PetrBečka)

在页面的div区域应用mouseenter事件遇到了一些麻烦我正在尝试在鼠标输入时更改此div的背景颜色,但都被忽略了。

我有一个简单的HTML代码:

<div id="services" class="services">
  <div id="services-top">
    <h2>Services</h2>
  </div>
  <div id="services-content">
    <div id="services-content-left">
      <img id="services-content-right-img" class="img-circle" src="http://i.imgur.com/vN5m4vK.jpg" alt="empty">
      <h3>STUFF</h3>
    </div>
  </div>
</div>

和JS一起发生的事件:

$(document).ready(function() {
  $("services-content-left").mouseenter(function() {
    console.log("enter");
    $(this).css("background-color", "yellow");
  });
});

正如我之前所说,当我进入该div区域时,背景保持不变,没有任何更改。这里是一个例子。
你不知道如何解决吗?

大号

你只是错过了

在您的代码中,应改为$(“#services-content-left”)

$(document).ready(function() {
    $("#services-content-left").mouseenter(function() {
        console.log("enter");
        $(this).css("background-color", "yellow");
    });
});

表示一个ID选择器。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章