我想只選擇與類X匹配的元素,並且沒有的任何也具有類X的兄弟。在我的示例中,X = hasDatepicker
。這是我想出來的:jQuery:選擇沒有該類的兄弟的類X的元素
$('.hasDatepicker:not(.hasDatepicker ~ .hasDatepicker)')
然而,這並不排除第一要素,所以在任何一組datepickers的,這仍然會選擇第一個。我不想包括任何組中的任何人,只有單身。
實施例與匹配度:
<div class="input text">
<input name="data[Goal][date_started]" type="text" value="" class="hasDatepicker" style="display: none; ">
<button type="button" class="ui-datepicker-trigger"><img src="/themed/mocha/images/btn_calendar.png" alt="..." title="..."></button>
</div>
實施例與相配:
<div class="input text">
<input type="text" value="" id="GoalDateStarted" class="hasDatepicker"><input type="text" value="" class="hasDatepicker" style="display: none; ">
<input type="text" value="" class="hasDatepicker" style="display: none; ">
<input name="data[Goal][date_started]" type="text" value="" class="hasDatepicker" style="display: none; ">
<button type="button" class="ui-datepicker-trigger"><img src="/themed/mocha/images/btn_calendar.png" alt="..." title="..."></button>
</div>
任何想法?謝謝!
你能提供的HTML結構,哪些是你想匹配的元素的例子嗎? – 2012-04-13 18:27:25
@GaryGreen完成:) – Garrett 2012-04-13 18:35:07
那麼你希望基於你的例子,父div或hasDatepicker類的輸入選擇什麼元素? – j08691 2012-04-13 18:41:01