:jQuery的濾波第n個孩子(N + X)沒有返回鑑於以下標記預期結果
<dl>
<dt>What are your hours?</dt>
<dd class="first">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="second">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="third">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="fourth">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="fifth">We are open 24/7.</dd>
</dl>
console.log($('dd').get());
//returns - [dd.first, dd.second, dd.third, dd.fourth, dd.fifth]
使用此選擇器添加一個類「隱藏」的$('dd').filter(':nth-child(n+4)').addClass('hide');
類適用於第二,第三,第四和第五。它是否不適用於第四和第五類?就好像$('dd')選擇器在count中包含了dt元素。爲什麼這樣呢?
<dl>
<dt>What are your hours?</dt>
<dd class="first">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="second hide">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="third hide">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="fourth hide">We are open 24/7.</dd>
<dt>What are your hours?</dt>
<dd class="fifth hide">We are open 24/7.</dd>
</dl>
因此,釋義 - 第n個孩子計算父母的所有元素,這也包括dt指數。 ? – seasick
@seasick是的! –