I’m trying to use jQuery (a bit difficult because I’m a complete novice) to select classes on a page and add different classes depending on their order.
Example:
<article class="news-story">
</article>
<article class="news-story">
</article>
<article class="news-story">
</article>
<article class="news-story">
</article>
I want jQuery to fetch all the “news-story” classed elements and add “customclass1” to the first, “customclass2” to the second, “customclass3” to the third and “customclass4” to the fourth.
Can anyone help me out with this please?
If you do I promise as soon as I resuscitate my PC I’m going to cram jQuery and PHP so hard my head will spin.
Thanks in advance.
You may use
addClass()method’s argument: