I've got multiple music players on a page and need to make an index of them to pull the position of the current player from. The issue is that the currentPlayer
is not a child, so using .find
or .filter
and then .index
will always return a value of 0
because nothing else is in the array.
So I need to find .currentPlayer
's index within the player
array.
HTML (very simplified):
<ul>
<li>
<article>
<div class="player"></div>
</article>
</li>
<li>
<article>
<div class="player currentPlayer"></div>
</article>
</li>
<li>
<article>
<div class="player"></div>
</article>
</li>
</ul>
JavaScript:
var player = $('.player'),
current = player.filter('.currentPlayer'),
index = current.index();