是否有任何方法將點擊事件附加到幾個元素,然後讓所有子元素(除了點擊這個元素的子元素)運行一個函數?jQuery選擇器不是這個孩子
這是一個可怕的解釋,但我正在尋找這樣的事情:
$(".block_header").click(function(){
$(".block_header span:not(this span)").toggleClass("collapse expand");
$(".container:not(this+div.container)").slideToggle();
});
下面是一個示例HTML:
<h3 id="sender_header" class="block_header"><span>Sender</span></h3>
<div id="sender_container" class="container">
<p>Show or hide this, based on which H3 is clicked.</p>
</div>
<h3 id="receiver_header" class="block_header"><span>Receiver</span></h3>
<div id="receiver_container" class="container">
<p>Show or hide this, based on which H3 is clicked.</p>
</div>
<h3 id="delivery_header" class="block_header"><span>Delivery</span></h3>
<div id="delivery_container" class="container">
<p>Show or hide this, based on which H3 is clicked.</p>
</div>
<h3 id="items_header" class="block_header"><span>Items</span></h3>
<div id="items_container" class="container">
<p>Show or hide this, based on which H3 is clicked.</p>
</div>
.... etc, etc (many more of the same)
希望這不是太複雜了。它會爲我節省很多代碼。
輝煌!非常感謝。 –
謝謝,我發現這非常有幫助 – esd