如何选择除我在jquery中悬停的元素之外的所有元素

How to pick all elements but the one i hover in jquery

本文关键字:元素 悬停 jquery 何选择 选择      更新时间:2023-09-26

当鼠标悬停在某个div上时,我想让.html文件中的所有div都消失。换句话说,有没有类似$(this),的东西,而不是其他所有div的
提前谢谢。

尝试

var div_all = $('div'); //refers to all div
div_all.hover(function () {
    div_all.not(this).hide(); //hide all div's but not current one
    $(this).show(); //$(this) refers to current div and show current div
}, function () {
    div_all.hide(); //hide all divs
});


div_all.not(this)指除悬停的div之外的所有div。
参考

这个关键字

.not()

.haverage()

$('div').hover(
    function(){ $('div').not(this).hide(); },
    function(){ $('div').show(); }
);