以下のスクリプトを使用して開発されたアコーディオンメニューがあります
$(document).ready(function(){
$('li.button a').click(function(e){
$(this).addClass('active');
/* Finding the drop down list that corresponds to the current section: */
var dropDown = $(this).parent().next();
/* Closing all other drop down sections, except the current one */
$('.dropdown').not(dropDown).slideUp('100');
dropDown.slideToggle('100');
/* Preventing the default event (which would be to navigate the browser to the link's address) */
e.preventDefault(); })
});
メニューがクリックされたときに.activeクラスを追加する必要があるので、jqueryにaddclassを追加しました。これはクラスを追加していますが、問題は、別のメニューがクリックされたときにクラスを削除する必要があることです。トグルクラスも試しましたが、うまくいきませんでした。
また、ページを開いたときにデフォルトで最初のliアイテムを開くようにします。