jQuery - 将元素悬停以向其添加类?

标签 jquery css jquery-selectors

$(".test").hover(function(){
  $(this).addClass("move");        
})

上面的 jQuery 需要一些修复。我的 CSS 选择器目前是这样的:

.test .selectme

并将鼠标悬停在 .test 上元素当前导致:

.test.move .selectme

当鼠标悬停在 .test 上时,我正试图获取此信息元素:

.test .selectme.move

所以基本上我需要 jQuery 来提供 .selectme .move当我将鼠标悬停在 parent 上时上课.test .

最佳答案

您需要在 menu 中找到 selectme 项,然后将类添加到其中

$(".menu").hover(function(){
  $(this).find('.selectme').addClass("move"); //You may use toggleClass('move') if you want to remove the class when the mouse leaves menu item
})

关于jQuery - 将元素悬停以向其添加类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464917/

相关文章:

javascript - '$' 在定义之前就被使用了

html - wrapper 的高度不适用于容器

jquery - jquery 中是否有一个类选择器但没有一个 id

jquery - 如何使用 jQuery 选择上下文节点的特定同级节点?

javascript - 显示下一个不是兄弟元素的元素

javascript - 针对引荐来源网址字符串进行正则表达式检查

javascript - 为什么这个 html/JavaScript 组合会这样打印?

jquery - 如果页面 h1 包含特定单词,则显示特定图像?

jQuery/CSS : Making the autocomplete push other divs down?

php - 使用 php 在 html 文本框中检索 mysql 表值