gpt4 book ai didi

javascript - 单击按钮时显示 div

转载 作者:行者123 更新时间:2023-11-28 19:40:46 25 4
gpt4 key购买 nike

我只是想toggle() <div class="reveal">当按钮被按下时。

我将有多个按钮和相应的<div>在页面上,所以我只想toggle()页面上的下一个实例使用 $(this).next("div.reveal").toggle();

什么也没发生,也没有错误。我做错了什么?

HTML:

<article class="customerQuotes">
<blockquote>Blah
<cite><b>Name</b> - Company</cite>
</blockquote>
<button class="button right">More</button>

</article>

<div class="reveal">
<div class="right">
//stuff here
</div>
</div>

JS:

$(".button").click(function() {
$(this).next("div.reveal").toggle();
});

CSS:

 .reveal{
display: none;
float: left;
clear: both;
}

最佳答案

您需要在父元素上调用 .next,因为 .reveal 是其同级元素。

$(".button").click(function() {
$(this).parent().next("div.reveal").toggle();
});

关于javascript - 单击按钮时显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25089219/

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