I have 5 li
elements, while I click on each of them, I am adding a class name on
and push it into an array. I would like to remove the item from the object when a user is clicking again.
<ul>
<li class="on" data-index="3">add 3</li>
<li data-index="4">add 4</li>
<li data-index="5">add 5</li>
<li class="on" data-index="6">add 6</li>
</ul>
When a user clicks on a li
I add a class called on
and push the value into an array and sort the array after I pushed the item.
If a user clicks again on the li
I can't remove the value from the array, because of the sort. Is there a way I can achieve this?
I don't have any idea to do the functionality regarding this.. any one can help me? I tried with splice, but no result.