ユーザーが「展開 [+]」をクリックしたときに折りたたんで展開したいページに多数の div があります。
次のコードは、1 つの div に対して機能します
<h4 class="expanderHead" style="cursor:pointer;">Contact information <span class="expanderSign">Expand [+]</span></h4>
<div id="profile-section" style="overflow:hidden;">
some stuff
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".expanderHead").click(function(){
if (jQuery(".expanderSign").text() == "Expand [+]")
{
jQuery("#profile-section").removeClass("height-min");
jQuery("#profile-section").addClass("height-auto");
}
else
{
jQuery("#profile-section").removeClass("height-auto");
jQuery("#profile-section").addClass("height-min");
}
if (jQuery(".expanderSign").text() == "Expand [+]"){
jQuery(".expanderSign").text("Collapse [-]");
}
else {
jQuery(".expanderSign").text("Expand [+]");
}
});
});
</script>
ページに多数の div がある場合
<h4 class="expanderHead" style="cursor:pointer;">Contact information <span class="expanderSign">Expand [+]</span></h4>
<div id="profile-section1" style="overflow:hidden;">
some stuff
</div>
<h4 class="expanderHead" style="cursor:pointer;">Contact information <span class="expanderSign">Expand [+]</span></h4>
<div id="profile-section2" style="overflow:hidden;">
some stuff
</div>
<h4 class="expanderHead" style="cursor:pointer;">Contact information <span class="expanderSign">Expand [+]</span></h4>
<div id="profile-section3" style="overflow:hidden;">
some stuff
</div>
etc....
これらすべての div で個別に機能するように jquery を変更するにはどうすればよいですか。つまり、クリックされた div のみを最小化または最大化しますか?
(this) と parent() と child() を使用してさまざまな組み合わせを試しましたが、うまくいかないようです。
助けていただければ幸いです:)