Potrzebuję skrypt jquery, aby dynamicznie dodać klasę do "div's" w wierszu klasy. Klasa służy do ustawiania marginesów. Jeśli istnieją dwa div w klasie, dodaj klasę tylko do pierwszej, a jeśli istnieją trzy klasy "div" dodaj dwie trzecie.Dodaj klasy dynamicznie do dzieci przez zapętlenie przez div
Zatem rzeczywistą potrzebą jest obliczyć div's w "wierszu" i dodać klasy do div inne niż ostatnie. Tu jest mój 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>
Czy zajęcia * faktycznie * muszą być dynamicznie dodawane czy to tylko przypadek, nie wiedząc, jak zastosować CSS do wszystkiego, ale ostatniego dziecka z kolekcji więc jesteś uciekania się do JS to włamać? Jeśli musi być dynamiczny, bardziej efektywne byłoby zastosowanie klasy do rodzica ('.row') i modyfikowanie stylów za pomocą' .row.newClass .one-col' lub podobnego selektora. – cimmanon