[英]faq toggle div show/hide + change link text
I watched/read/search many tutorials, but with no luck. 我看过/读过/搜索过很多教程,但是没有运气。 I stick with this tutorial .
我坚持使用本教程 。
I am trying to apply toogle acordion effect with JS (possibly CSS only) without targeting to divs. 我正在尝试对JS(可能仅CSS)应用toogle acordion效果, 而不定位到div。
There are 2 options to show content: 有两种显示内容的选项:
I don't mind, which option you choose to solve this problem. 我不介意,您选择了哪个选项来解决此问题。
I can't change any atribute to ID elements (eg id="div1", id="div2", ...) 我无法更改 ID元素的任何属性 (例如id =“ div1”,id =“ div2”,...)
My goal is to make something like in picture: 我的目标是制作类似图片的图片:
<div class="widget widgetFaq clearfix">
<div class="widgetTitle">
<h2>FAQ</h2>
</div>
<div class="widgetContent clearfix">
<div class="box boxFaq clearfix">
<div class="boxTitle">
<h3>Question one?</h3>
<button> show </button>
</div>
<div class="boxContent clearfix toggle">
<p>Answer to the question. Answer to the question. Answer to the question. </p>
</div>
</div>
<div class="box boxFaq clearfix">
<div class="boxTitle">
<h3>Question second?</h3>
<button> show </button>
</div>
<div class="boxContent clearfix toggle">
<p>Answer to the question. Answer to the question. Answer to the question. </p>
</div>
</div>
</div>
</div>
$(document).ready(function(){
$('button').click(function() {
$(this).next('.toggle').slideToggle();
});
});
( put <button>show</button>
after boxTitle
div ) (将
<button>show</button>
boxTitle
div之后)
$(document).ready(function() {
$('button').click(function() {
$(this).next('.toggle').slideToggle();
if ($(this).text() === '+') {
$(this).html('-');
}
else {
$(this).html('+');
}
});
}); });
$(this).parent().next('.toggle').slideToggle();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.