I created jQuery function
function starsMouseMove(n) {
var i = $(this).offset().left,
t = Math.floor((n.pageX - i)),
w;
if (t > 0 && t < 20) {
w = 20;
} else if (t >= 20 && t < 40) {
w = 40;
} else if (t >= 40 && t < 60) {
w = 60;
} else if (t >= 60 && t < 80) {
w = 80;
} else if (t >= 80 && t <= 100) {
w = 100;
}
$(".stars_width", $(this)).css("width", w + "%");
$(this).parent().find('#rating-input').val(w / 10);
};
and then I try to use it on hover
$('.stars').hover(function (n) {
starsMouseMove(n);
});
but I get an error
Uncaught TypeError: Cannot read property 'left' of undefined
What's wrong? How to fix it?
thisin functionstarsMouseMove(n)is$('.stars')this, you would have discovered it wasWindow