Add class (odd and even) in html via javascript? -
i have code example:
<section class="timeline"> <article class="post "> <article class="post "> <article class="post "> <article class="post "> </section>
now want know how add class via javascript article element. example:
1st article add class "left"
2nd article add class "right"
3rd article add class "left"
4th article add class "right"
i'm not sure want don't need have javascript can write styles odd , childrens.
.post:nth-child(odd) { color: green; } .post:nth-child(even) { color: red; }
<section class="timeline"> <article class="post ">article</article> <article class="post ">article</article> <article class="post ">article</article> <article class="post ">article</article> </section>
Comments
Post a Comment