I am trying to add the class last dynamically to every second row with jQuery as below
<div class= "news-row">
<article class="news-container fixed-page"> blah blah</article>
<article class="news-container fixed-page"> blah blah2</article>
</div>
Below is the jquery
<script type="text/javascript">
$(document).ready(function () {
$('article.news-container :nth-child(2n)').addClass('last');
});
</script>
This does not add the class. Any help will be appreciated. I want the every second article element to have "last" appended.
$object forarticle.news-container :nth-child(2n). Check what does it resolve to usingconsole.log.:eveninstead ofnth-child.