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

Popular posts from this blog

c# - ItextSharp font color issue in ver 5.5.4+ -

jquery - Multiple issues with pushstate: history, loading, calling functions -

ios - retrievePeripherals deprecated in IOS7 how to substitude it with retrievePeripheralsWithIdentifiers -