Javascript jQuery切换更多按钮切换多个div
我已经为切换按钮编写了jqueryJavascript jQuery切换更多按钮切换多个div,javascript,jquery,toggle,Javascript,Jquery,Toggle,我已经为切换按钮编写了jquery $(document).ready(function(){ /* Needs to be re-written for multiple questions */ $(".full_question").hide(); $('.question a').after('<a class="show_full_question" href="#">more</a>'); $('.show_full_ques
$(document).ready(function(){
/* Needs to be re-written for multiple questions */
$(".full_question").hide();
$('.question a').after('<a class="show_full_question" href="#">more</a>');
$('.show_full_question').click(function() {
var el = this;
$(".full_question").toggle(function() {
$(el).text($(el).text() == 'less' ? 'more' : 'less');
$(el).toggleClass("hide_full_question");
});
});
});
$(文档).ready(函数(){
/*需要重新编写多个问题*/
$(“.full_question”).hide();
$('问题a')。在('')之后;
$('.show_full_question')。单击(函数(){
var el=这个;
$(“.full_question”).toggle(函数(){
$(el).text($(el).text()=='less'?'more':'less');
$(el).toggleClass(“隐藏完整问题”);
});
});
});
它在整个问题宽度和部分宽度之间切换。但当点击时,它会切换页面上的所有问题。我怎样才能得到它呢
我知道这和美元有关,但我不知道它去了哪里。。。如果有必要,我不介意更改html
html是
<h3 class="question">
<a href="#">What size is the circumference of the earth? I don't really know what it is! Help me! What size is the...
<span class="full_question"> circumference of the earth? I really don't know!</span>
</a>
</h3>
问题是$(“.full\u question”)。toggle()
将使用full\u question
类切换所有元素。您需要以某种方式将当前单击的元素与适当的完整问题链接起来
由于在同一父项下有一个full_question
和一个show_full_question
按钮,因此可以使用jQuery获取父项并查找要切换的问题:
$(this).parent().find(".full_question").toggle()
如果您确定HTML结构不会改变,您还可以执行以下操作:
$(this.previousSibling.childNodes[1]).toggle()
这里有一个。你能不能也添加html代码(或一个代码片段)是的,为问题发布html