Es muss etwas Einfaches fehlen, das ich vermisse. Ich versuche, den Index des Elements zu erhalten, aber immer -1 erhalten.Problem mit jQuery-Index()
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');
});
Ich würde diese 20 mal upvote wenn ich könnte. .index() ergibt keinen Sinn. – nipponese
Toller Ansatz! – Alexander