ユーザーがクリックすると展開するアイテムを含むメニューをいくつか作成しました。メニュー項目が展開されるたびに、項目の見出しは.css()を使用してスタイルを変更することになっています。
メニューのスタイルが異なるため、スクリプト内にifステートメントがあり、ユーザーがmenu2またはmenu3の項目をクリックして、展開時に適切なスタイルを適用したかどうかを確認します。
編集:問題は、スタイルの変更が適切に適用されないことです。
Sushanthが提案したように、$ thisを$(this)に置き換えましたが、問題は解決しません。例を確認してください(更新)
コード:
<script type='text/javascript'>
$(window).load(function(){
$(document).ready(function() {
$(".toggle-trigger").click(function() {
$(this).parent().nextAll('.toggle-wrap').first().slideToggle('slow','swing');
if( $(this).is("menu2 .headline a")) {
$(this).toggle(
function(){
$(this).parent().css("background-color","rgba(0, 0, 0, 0.1)",'border', 'solid 2px #009e0f');
$(this).css("color","#009e0f");
},
function(){
$(this).parent().css("background-color","#009e0f","border",'solid 2px #009e0f');
$(this).css("color","#ffffff");
}
);
}
else if( $(this).is("#menu3 .headline a")) {
$(this).toggle(
function(){
$(this).parent().css("background-color","rgba(0, 0, 0, 0.1)",'border', 'solid 2px #f7b50c');
$(this).css("color","#f7b50c");
},
function(){
$(this).parent().css("background-color","#009e0f","border",'solid 2px #f7b50c');
$(this).css("color","#ffffff");
}
);
}
});
});
});