There must be something simple I am missing. I'm trying to get the index of the element but keep getting -1.
HTML:
<div id="rating_boxes">
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
<img src="/img/ratingbox.gif" class="ratingbox" alt="Rate this Speech" />
</div>
jQuery:
$("img.ratingbox").hover(function() {
var index = $(this).parent().index(this);
// have also tried $("#rating_boxes").index(this);
// and $("#rating_boxes").index($(this));
// and $(this).parent().index($(this));
alert(index);
$(this).attr('src', '/img/ratingbox-selected.gif');
}, function() {
$(this).attr('src', '/img/ratingbox.gif');
});