我有下面的HTML結構jQuery選擇了與經常性的元素相同的元素
現有
<fieldset>
....
<div>
<div class="responsive"></div>
</div>
...
<fieldset>
....
<div class="responsive"></div>
</fieldset>
...
<div class="responsive"></div>
<fieldset>
<div>
<div class="responsive"></div>
</div>
</fieldset>
</fieldset>
<div class="responsive"></div>
<fieldset>
.....
<div class="responsive"></div>
<div class="responsive"></div>
<fieldset>
........
<div class="responsive"></div>
<fieldset>
........
<div class="responsive"></div>
</fieldset>
</fieldset>
</fieldset>
<div class="responsive"></div>
編輯
1)。響應可能有任何沒有。父母直到.reponsive和字段集之間的字段集2)他們可能有兄弟姐妹在下面和後
我需要寫jQuery選擇在字段集,但到第1級找到.responsive只有這樣我應該修正寬度。即
fieldset -> .responsive (correct) (result may contain 1 or more)
fieldset -> .responsive -> fieldset -> .responsive (wrong)
.responsive (wrong)
但是通過這個選擇,我應該能夠僅在字段集選擇所有.responsive DIV與和保持寬度它。
預期輸出
<fieldset>
....
<div>
<div class="responsive" style="width:xpx;"></div>
</div>
...
<fieldset>
....
<div class="responsive" style="width:yzpx;"></div>
</fieldset>
...
<div class="responsive"></div>
<fieldset>
<div>
<div class="responsive" style="width:xypx;"></div>
</div>
</fieldset>
</fieldset>
<div class="responsive"></div>
<fieldset>
.....
<div class="responsive" style="width:xzpx;"></div>
<div class="responsive" style="width:zpx;"></div>
<fieldset>
........
<div class="responsive" style="width:xzpx;"></div>
<fieldset>
........
<div class="responsive" style="width:yzpx;"></div>
</fieldset>
</fieldset>
</fieldset>
<div class="responsive"></div>
你試過'$( 「字段集> .responsive」)'? – vijayP
hi vijay,讓我試試,如果這符合我的要求,請檢查預期的輸出,因爲我剛剛添加 –
hello Pavan,我已經添加了片段,以便您可以在此處進行測試。 – vijayP