gpt4 book ai didi

jQuery:选择除下一个之外的所有元素

转载 作者:行者123 更新时间:2023-12-01 03:22:05 25 4
gpt4 key购买 nike

我有以下标记:

<!-- first marker -->
<div class="marker"></div>
<div class="tooltip">
<p>My tooltip content"</p>
</div>

<!-- second marker -->
<div class="marker"></div>
<div class="tooltip">
<p>My tooltip content"</p>
</div>

<!-- repeating..... -->

以及以下 jQuery javascript:

$(document).ready(function() {

$(".marker").hover(function(event){
$('.tooltip').hide();
$(this).next('.tooltip').slideDown('fast');
});

});

如何修改此脚本,以便在悬停时隐藏除下一个之外的所有其他打开的 div.tooltips?目前它试图隐藏所有内容。

最佳答案

您可以使用not函数省略特定元素

$(".marker").hover(function(event){
var nextEl = $(this).next("div.tooltips");
$('.tooltip').not(nextEl).hide();
$(this).next('.tooltip').slideDown('fast');
});

编辑

此外,您可能还需要向 hover 传递第二个函数,以便在悬停结束时清理内容:

$(".marker").hover(function(event){
var nextEl = $(this).next("div.tooltips");
$('.tooltip').not(nextEl).hide();
$(this).next('.tooltip').slideDown('fast');
}, function() {
$('.tooltip').hide();
});

关于jQuery:选择除下一个之外的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8838531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com