Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用'对同一类的各个div执行Jquery函数;这';选择器_Jquery_Class_Html - Fatal编程技术网

使用'对同一类的各个div执行Jquery函数;这';选择器

使用'对同一类的各个div执行Jquery函数;这';选择器,jquery,class,html,Jquery,Class,Html,我试着在图像上做一个简单的覆盖,这个函数可以很好的工作,但是会出现在所有的div中。我希望函数在悬停的div上运行,而不是在所有具有相同类的div上运行 我使用这个简单的函数来内联应用.css $(document).ready(function() { $('.attachment-home-sub-feature, .thumb-hover').hover(function() { $('.thumb-hover').css({ 'displa

我试着在图像上做一个简单的覆盖,这个函数可以很好的工作,但是会出现在所有的div中。我希望函数在悬停的div上运行,而不是在所有具有相同类的div上运行

我使用这个简单的函数来内联应用.css

$(document).ready(function() {
    $('.attachment-home-sub-feature, .thumb-hover').hover(function() {
        $('.thumb-hover').css({
            'display': 'block'
        });
    }, function() {
        $('.thumb-hover').css({
            'display': 'none'
        });
    });
});​
HTML:

<div class="sfp-img">
<div class="thumb-hover"><a class="thumb-hover-link" href="<?php the_permalink() ?>"></a></div><?php if ( has_post_thumbnail()) the_post_thumbnail('home-sub-feature'); ?>
</div>

使用
$(此)

看看-

编辑:

在阅读了你的评论之后,我认为还有另一种方法可以做到这一点。 在CSS中,不要只使用
拇指悬停
创建两个类:

1.
thumb-regular

2.
拇指悬停

其中一个具有显示块,另一个具有显示无。 在jQuery中,不要使用
css()
,而是使用
addClass
removeClass

(但仍要像上面的代码一样使用

这不起作用,因为它只是隐藏了图像。我有一个图像,它是.attachment home子功能和.thumb悬停被隐藏,但定位在图像上方。悬停图像时,将显示拇指悬停。我想我找到了。你能编辑你的问题并添加你的HTML代码吗?考虑从你的网页的<代码>视图源< /代码>中添加HTML,而不是直接从你的文件中添加HTML。我编辑了我的答案,帮了忙?不知道为什么我第一次这样尝试时它不起作用,但现在它起作用了。
$(document).ready(function() {
    $('.attachment-home-sub-feature, .thumb-hover').hover(function() {
        $(this).css({
            'display': 'block'
        });
    }, function() {
        $(this).css({
            'display': 'none'
        });
    });
});​