当用户单击其相应的父 DIV 时,我试图显示/隐藏 DIV。
HTML:
<div class="header" id="header_1"> </div>
<div class="body" id="body_1"> </div>
<div class="header" id="header_2"> </div>
<div class="body" id="body_2"> </div>
jQuery:
$('.body')hide(); <--- hide all on load
$('.header').click(function(){
var currentHeader = $(this).attr('id');
//some logic to show the body div below the header that was clicked, and hide all the others
});