gpt4 book ai didi

javascript - 从下一个元素 jQuery 中删除类

转载 作者:行者123 更新时间:2023-11-28 05:43:02 25 4
gpt4 key购买 nike

我有一个这样的html:

<div class="results">
<div class="resultitem" page="1">
<div class="col-sm-12 odd">
<div class="col-sm-2 noLRPadding"><p class="memFName">Arsene</p></div>
<div class="col-sm-2 noLRPadding"><p class="memLName">Wenger</p></div>
<div class="col-sm-3 noLRPadding"><p class="memEmail">louise.lockie@wilmingtonplc.com</p></div>
<div class="col-sm-1 noLRPadding"><p class="memLevel">Affiliate</p></div>
<div class="col-sm-1 noLRPadding"><p class="memCPD">0</p></div>
<div class="col-sm-1 noLRPadding"><p class="memTarCPD">10</p></div>
<div class="col-sm-1 hidden noLRPadding"><p class="memDiff">10</p></div>
<div class="col-sm-1 noLRPadding"><p><a class="memLink" href="/my-membership/cpd-centre/cpd-log/?m=CON-000184210">View</a></p></div>
<div class="col-sm-1 noLRPadding text-center"><a class="showConfirm" href="#" data-user="CON-000184210" data-username="Arsene Wenger"><i style="font-size: 18px; color: #b43e91" class="fa fa-times-circle"></i></a></div>
</div>
<div class="logPanel hidden">
<p>Hello</p>
</div>
</div>
<div class="resultitem" page="1">
<div class="col-sm-12 odd">
<div class="col-sm-2 noLRPadding"><p class="memFName">Jack</p></div>
<div class="col-sm-2 noLRPadding"><p class="memLName">Wilshire</p></div>
<div class="col-sm-3 noLRPadding"><p class="memEmail">louise.lockie@wilmingtonplc.com</p></div>
<div class="col-sm-1 noLRPadding"><p class="memLevel">Affiliate</p></div>
<div class="col-sm-1 noLRPadding"><p class="memCPD">0</p></div>
<div class="col-sm-1 noLRPadding"><p class="memTarCPD">10</p></div>
<div class="col-sm-1 hidden noLRPadding"><p class="memDiff">10</p></div>
<div class="col-sm-1 noLRPadding"><p><a class="memLink" href="/my-membership/cpd-centre/cpd-log/?m=CON-000184209">View</a></p></div>
<div class="col-sm-1 noLRPadding text-center"><a class="showConfirm" href="#" data-user="CON-000184209" data-username="Jack Wilshire"><i style="font-size: 18px; color: #b43e91" class="fa fa-times-circle"></i></a></div>
</div>
<div class="logPanel hidden">
<p>Hello</p>
</div>
</div>

我想做的是在按下 memLink 链接时显示“隐藏”logPanel div,因此在脚本中我得到了:

$(".results").on("click", ".memLink", function (e) {
e.preventDefault();
$(this).nextAll('.logPanel').first().removeClass('hidden');
alert("hello");
});

但是尽管我可能进行调整,但我无法让它工作。请问有人可以解释一下吗?

谢谢,克雷格

最佳答案

找到最近类“resultitem”,然后找到所需的第一个元素

    $(this).closest(".resultitem").find(".logPanel:first").removeClass('hidden');

关于javascript - 从下一个元素 jQuery 中删除类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38764033/

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