jquery - 使用 JQuery 仅显示/隐藏一个 DIV

标签 jquery css html hover

我有一页图像,我想在鼠标悬停时显示/隐藏标签。图像也是链接,div 称为“.smallproj”。 JQuery 脚本运行良好,但当我将鼠标悬停在 .smallproj a 的任何一个实例上时,当然会显示 .smallproj p 的所有实例。我知道我需要更改脚本,以便只显示悬停在上方的 .smallproj 实例,但在这种情况下最好的方法是什么?

JQuery 脚本:

$(".smallproj a").on({
    mouseover: function() {
        $(".smallproj p").show();
    },      
    mouseout: function() {
        $(".smallproj p").hide();
    }       
});  

最佳答案

我认为你可以:

$('.smallproj p').hover(function(){
  $(this).show();
});

或者,看起来您还想将鼠标悬停在链接上,所以请尝试:

$('.smallproj a').hover(function(){
  $(this).find('p').show();
});

关于jquery - 使用 JQuery 仅显示/隐藏一个 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15030409/

相关文章:

jquery - Bootstrap 标签输入无法使用文档就绪

jQuery:串联导致未定义

html - 为什么我在 :hover tag? 上有这种奇怪的 CSS 行为

选择新元素时关闭 jQuery 切换类

javascript - jQueryMobile - 滚动到一个位置 onLoad

javascript - 一个随机数自动附加到一个js文件

html - 为什么我的导航不像其他所有东西一样居中

html - 与其他元素分组后更改元素属性

html - 仅在标题内制作图片可点击的 css/html

javascript - jQuery 上下文未按预期工作