jquery - 选择类中的特定元素

标签 jquery jquery-selectors

我是 jQuery 的初学者,我在尝试解决这个问题时遇到了一些困难:

所以我有类似的东西:

<div class="app">
<div class="app-text"></div>
</div>

<div class="app">
<div class="app-text"></div>
</div>

我想使用 jquery 来更改 .app-text 的颜色,但是当使用 .app-text 时,它也会更改另一个 div 中的 app-text (显然),那么我如何只更改 .app-text 的颜色呢?悬停在 .app div 内的 app-text。鼠标悬停在 .app div 上时需要触发该事件。

(同一页面上会有相当多的.app div)

最佳答案

您可以使用$(选择器,上下文):

$('.app').hover(function(){
   $('.app-text', this).foo()
  }, function(){
   $('.app-text', this).bar()
})

关于jquery - 选择类中的特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11844447/

相关文章:

javascript - 选择器的 jQuery 串联而不创建新实例?

jQuery : eq() vs get()

jquery - iPhone 上的 HTML5 Canvas 在 touchstart/mousedown 事件上突出显示

jquery - 仅允许 onclick 一次

javascript - 在我的自定义模态框内滚动

javascript - 显示条件字段 onload 的 Jquery 脚本

javascript - 使用 jQuery Sortable 更改 CSS

jquery - 比较 2 个表的值并突出显示不同的行

jquery - 如何从下拉列表中选择特定值

jQuery 将类添加到嵌套列表中的所有最后一个子级