前提
jQueryで、よくあるアコーディオンメニューを作成しています。項目を押すと+ボタンがマイナスに変わり、下に回答がスライドで出てくるアコーディオンメニューです。何度か同じようなものを作成したことがあり今回もそれに習って作成したのですが、どうしても動かず、どこに原因がありそうか教えていただけましたら幸いです。
実現したいこと
アコーディオン作成
該当のソースコード
<section class="other"> <div class="contents_width"> <h3>A</h3> <div class="other_acd"> <dl class="first open"> <dt class="shadow">テキスト</dt> <dd>テキストテキスト</dd> </dl> <dl class="open"> <dt class="shadow">テキスト</dt> <dd>テキストテキスト</dd> </dl> </div> </div> </section>
.other{ margin: 17.5rem 0 0 0; padding: 3.2rem 0 10rem 0; } .other .first{ margin-top: 4.7rem; } .other_acd dt{ color: #000; font-size: 2.4rem; font-weight: 700; background: linear-gradient(to right, #f6f3dc 0%, #f6efb8 70% ,#e6dfad 100%); padding: 1.4rem 0 1.4rem 5rem; margin-top: 3rem; position:relative; } .other_acd dt::after{ text-align: center; line-height: 1.7; content: "-"; position: absolute; top: 0.9rem; right: 5rem; background-color: #0097a7; background: linear-gradient(to right, #ebe4af 0%,#e6dfad 100%); width: 4.4rem; height: 4.4rem; border-radius: 50%; border: 1px solid; } .other_acd dd{ color: #000; background-color: #fff; padding: 2.4rem 6rem 2.4rem 5.1rem; margin-top: 1rem; line-height: calc(28/16); display: none; } .other_acd dl.open dt::after { content: '+'; }
$(".other_acd dt").on("click",function () { $(this).parent().toggleClass("open"); $(this).next().slideToggle(); });
試したこと
console.log等で動くか確認→反応しないので、恐らく要素の捕まえ方に問題があると認識はしております。クリックする要素にクラス名をつけたり、要素の絞り方を変えたり色々試してみました。googleでも相当調べました。また、他のjQueryでの処理は動いているので読み込みに問題はないと思います。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー