我想選擇一個特定的div,當點擊一個按鈕...唯一的問題是,它必須是buttonClicked的父div的div ...示例:jQuery - 在同一級別選擇div
<div class="container">
<div class="box">
<h2>Langtidsparkering</h2>
<div class="content">
Lorem ipsum dolor sit amet..
</div>
</div>
<div class="listcontainer">
<div class="list"> (THIS DIV SHOULD GET A CLASS "VISIBLE", WHEN THE BUTTON IS CLICKED)
</div>
<div class="listbar">
<button class="viewPrices" type="submit" title="Open">Se priser<span></span </button>
</div>
</div>
</div>
代碼:
$(".viewPrices").click(function() {
$(".viewPrices").parents('.listaccordion .list').toggleClass('visible');
});
有什麼建議? :-)
請添加演示小提琴。 – Quinn
Whops ... take this http://jsfiddle.net/unebune/n264v/1/ – unebune
'$(this).closest('.listbar')。prev()' – adeneo