1

4 つのアコーディオン スタイルで WordPress テーマを作成しようとしています。コードを短くするためにコードをいじってみましたが、何もしませんでした。これを短くする方法はありますか?あなたの助けに感謝します!

jQuery(document).ready(function() {
    var allPanels = jQuery('.accordion-style1 > dd').hide();
    jQuery('.accordion-style1 > dt > a').click(function() {
        allPanels.slideUp();
        if(jQuery(this).parent().next().is(':hidden')) {
            jQuery(this).parent().next().slideDown();
        }
        return false;
    });
});

jQuery(document).ready(function() {
    var allPanels = jQuery('.accordion-style2 > dd').hide();
    jQuery('.accordion-style2 > dt > a').click(function() {
        allPanels.slideUp();
        if(jQuery(this).parent().next().is(':hidden')) {
            jQuery(this).parent().next().slideDown();
        }
        return false;
    });
});

jQuery(document).ready(function() {
    var allPanels = jQuery('.accordion-style3 > dd').hide();
    jQuery('.accordion-style3 > dt > a').click(function() {
        allPanels.slideUp();
        if(jQuery(this).parent().next().is(':hidden')) {
            jQuery(this).parent().next().slideDown();
        }
        return false;
    });
});

jQuery(document).ready(function() {
    var allPanels = jQuery('.accordion-style4 > dd').hide();
    jQuery('.accordion-style4 > dt > a').click(function() {
        allPanels.slideUp();
        if(jQuery(this).parent().next().is(':hidden')) {
            jQuery(this).parent().next().slideDown();
        }
        return false;
    });
});

http://jsfiddle.net/michellecantin/4mYdn/

4

3 に答える 3