mardi 28 novembre 2017

How to check if the element selected/clicked is multiple of "n" using jquery?

I have 'n' li elements inside a ul. I want to alert a message only if the li selected/clicked is a multiple of "n"(let it be 3).

In the below example, the alert must be shown only if I click the 3rd, 6th, and 9th li element:

<ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li>list item 3</li>
    <li>list item 4</li>
    <li>list item 5</li>
    <li>list item 6</li>
    <li>list item 7</li>
    <li>list item 8</li>
    <li>list item 9</li>
</ul>




Aucun commentaire:

Enregistrer un commentaire