divをクリックして、彼の子供を表示させたいと思います。問題は、私がそれらのdivの長いリストを持っていることです。各divには子があります。以下では、divの「エチケット」をクリックして、子のdivの「詳細」を表示または非表示にします。
<div class="etiquette">
<span class="date">13-07</span>
<span class="titre">LOREM IPSUM 1</span>
<div class="detail"><p>lorem ipsum 1</p></div>
</div>
<div class="etiquette">
<span class="date">14-07</span>
<span class="titre">LOREM IPSUM 2</span>
<div class="detail"><p>lorem ipsum 2</p></div>
</div>
<div class="etiquette">
<span class="date">14-07</span>
<span class="titre">LOREM IPSUM 3</span>
<div class="detail"><p>lorem ipsum 3</p></div>
</div>
使用したいスクリプトは次のとおりです。
$(document).ready(function() {
$(".etiquette").children(".detail").css("display", "none");
$(this).toggle(function() {
alert("clicked");
$(this).children("div.detail").css("display", "block");
}, function() {
alert("clicked again");
$(this).children("div.detail").css("display", "none");
});
});
以下はうまく機能します:
$(this).toggle(function() {
alert("clicked");
});
以下もうまくいきます。ただし、クリックしたdivの子だけでなく、すべてのdivの「詳細」を表示または非表示にします。
$(this).toggle(function() {
alert("clicked");
$(".etiquette").children("div.detail").css("display", "block");
}, function() {
alert("clicked again");
$(".etiquette").children("div.detail").css("display", "none");
});
});
私は何を間違っているのですか?よろしくお願いします。