Newbie in Javascript and in English, please forgive my writing.
I've searched and came across many posts explaining how I should add a class but they are not the same as what I need to do.
I would like to add a specific class to every 4th li
that is displayed (or is visible), by which I mean, I have some li
that are not displayed and they should be excluded from the counter:
<section>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
<!--
window.onload=function(){
$('.liste li:nth-child(4)').addClass('lastli');
};
//-->
</script>
<ul class="liste">
<li>1 Lorem</li>
<li>2 ipsum</li>
<li>3 dolor</li>
<li style="display:none;">4 sin amet</li>
<li>5 consectetur</li> <!-- add a lastli class here -->
<li>6 aliquam</li>
<li style="display:none;">7 lobortis</li>
<li>8 Fusce</li>
<li>9 fringilla</li>
<li>10 rutrum</li> <!-- add a lastli class here -->
<li>11 dapibus</li>
<li style="display:none;">12 nunc</li>
<li>13 nunc</li>
</ul>
</section>