我需要一個jquery腳本來將類動態添加到類行中的'div'。這門課是爲了設定利潤。如果在類行中有兩個div,只向第一個類添加類,並且如果有三個'div'添加類到兩個,則避免第三個。通過div循環動態添加類到兒童
因此,實際需要是計算'行'的div並將類添加到除最後一個之外的div。這裏是我的html: -
<div class="row">
<div class="two-col">
<h3>Header 2/3 Column</h3>
<p>Kidney Cancer Canada is a charitable patient-led support organization established to improve the quality of life for patients and their
families living with kidney cancer. <a href="#">Kidney Cancer Canada</a> advocates for access to netreatments, provides support and information to patients,
funds much-needed research, and works to increase awareness of kidney cancer as a significant health issue. Our goal is to help patients navigate
through information about their disease and ensure they have access to new treatment options available to them.</p>
</div>
<div class="one-col">
<h3>Header 1/3 Column</h3>
<p>KCC hosts patient and caregiver education meetings and webcasts from locations all across canada. Atttending meetings in-person provides an
excellent oppurtunity to meet other kidney cancer patients, caregivers, and healthcare professionals</p>
</div>
<div class="clear"></div>
</div>
<div class="row">
<div class="one-col">
<h3>Header 1/3 Column</h3>
<p>KCC hosts patient and caregiver education meetings and webcasts from locations all across canada. Atttending meetings in-person provides an
excellent oppurtunity to meet other kidney cancer patients, caregivers, and healthcare professionals</p>
</div>
<div class="one-col">
<h3>Header 1/3 Column</h3>
<p>KCC hosts patient and caregiver education meetings and webcasts from locations all across canada. Atttending meetings in-person provides an
excellent oppurtunity to meet other kidney cancer patients, caregivers, and healthcare professionals</p>
</div>
<div class="one-col">
<h3>Header 1/3 Column</h3>
<p>KCC hosts patient and caregiver education meetings and webcasts from locations all across canada. Atttending meetings in-person provides an
excellent oppurtunity to meet other kidney cancer patients, caregivers, and healthcare professionals</p>
</div>
<div class="clear"></div>
</div>
別類* *實際需要動態增加或者這只是不知道如何應用CSS來的一切,但一個集合的最後一個孩子,所以你要訴諸的情況下, JS來破解它?如果它必須是動態的,則將該類應用於父級('.row')並通過'.row.newClass .one-col'或類似選擇器修改樣式會更有效。 – cimmanon