简体   繁体   English

全部展开-折叠全部Div样式问题

[英]Expand All - Collapse All Div Styling Issue

I am making an FAQ page with the answers collapsed and then a show all and hide all control for the questions/answers. 我正在制作一个FAQ页面,其中折叠了答案,然后全部显示并隐藏所有对问题/答案的控制。

My problem is that I am using a toggleClass to switch the '+' or '-' sign next to the question but when you click on the 'Show All Answers' or 'Hide All Answers' the class keeps toggling. 我的问题是我正在使用toggleClass在问题旁边切换“ +”或“-”符号,但是当您单击“显示所有答案”或“隐藏所有答案”时,该类仍在切换。

I am not a jquery master by any means. 无论如何,我都不是一个jQuery高手。

$(document).ready(function() {
$('.showThis').click(function() {

    $(this).next('.answer').slideToggle(500);
    $(this).toggleClass('showMinus');

});
$('#expandAll').click(function() {        
    $('.answer').slideDown();
     $('.showThis').toggleClass('showMinus');    
});
$('#collapseAll').click(function() {        
    $('.answer').slideUp();    
     $('.showThis').toggleClass('showMinus');    
}); }); // end ready

http://jsfiddle.net/ufe73cfb/2/ http://jsfiddle.net/ufe73cfb/2/

Try this. 尝试这个。 Fiddle 小提琴

$('#expandAll').click(function() {        
    $('.answer').slideDown();
     $('.showThis').addClass('showMinus');    
});
$('#collapseAll').click(function() {        
    $('.answer').slideUp();    
     $('.showThis').removeClass('showMinus');    
});

this will work for you, here is the DEMO 这将为您工作,这是演示

$(document).ready(function() {
    $('.showThis').click(function() {

        $(this).next('.answer').slideToggle(500);
        $(this).toggleClass('showMinus');

    });

    $('#expandAll').click(function() {  debugger;      
        $('.answer').slideDown();
         $('.showThis').addClass('showMinus');    
    });
    $('#collapseAll').click(function() {      debugger;  
        $('.answer').slideUp();    
         $('.showThis').removeClass('showMinus');    
    });
});

You neet addClass and removeClass instead of toggleClass. 您没有添加类,而是删除了class,而不是toggleClass。

$(document).ready(function() {
$('.showThis').click(function() {

    $(this).next('.answer').slideToggle(500);
    $(this).toggleClass('showMinus');

});
$('#expandAll').click(function() {        
    $('.answer').slideDown(500);
    $('.showThis').addClass('showMinus');
});
$('#collapseAll').click(function() {        
    $('.answer').slideUp();    
    $('.showThis').removeClass('showMinus');    
});

}) })

New fiddle: http://jsfiddle.net/ufe73cfb/6/ 新提琴: http : //jsfiddle.net/ufe73cfb/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM