I have this jQuery code that handles hovering over rating stars, when you hover they glow as they're meant to. Problem is, once you've taken your cursor out, it still displays what your cursor was on (and doesn't show the original rating). How can I make it check for when the cursor is removed, then show the original ratings?
$(document).ready(function() {
$("[id^=rating_]").hover(function() {
rid = $(this).attr("id").split("_")[1];
$("#rating_"+rid).children("[class^=star_]").children('img').hover(function() {
$("#rating_"+rid).children("[class^=star_]").children('img').removeClass("hover");
/* The hovered item number */
var hovered = $(this).parent().attr("class").split("_")[1];
while(hovered > 0) {
$("#rating_"+rid).children(".star_"+hovered).children('img').addClass("hover");
hovered--;
}
});
});
$("[id^=rating_]").children("[class^=star_]").click(function() {
var current_star = $(this).attr("class").split("_")[1];
var rid = $(this).parent().attr("id").split("_")[1];
$('#rating_'+rid).load('http://localhost:8888/fivestars/send.php', {rating: current_star, id: rid});
});
});
EDIT: Outputted HTML for something with a 3-star rating:
<div id="rating_3">
<span class="star_1"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_2"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_3"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" class="hover" /></span>
<span class="star_4"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" /></span>
<span class="star_5"><img src="http://localhost:8888/fivestars/star_blank.png" alt="" /></span>
</div>