DevStud DevStud - 27 days ago 13
jQuery Question

Proper event binding

I have a question about proper event binding. I shoved my js code he said


PROPER EVENT BINDING: Consider using the preferred .on() method rather
than .click(), .bind(), .hover(), etc.


$(".star").hover(
function() {
var prevStars = $(this).prevAll();
prevStars.toggleClass('rate-btn-hover');
}
);
$("body").on("click", ".star", function() {
$(this).siblings().removeClass('rate-btn-active')
var prevStars = $(this).prevAll().addBack();
prevStars.addClass('rate-btn-active');
});


Can anyone tell me what that means ?

Answer

The text of the message is suggesting substituting

.on("mouseeneter", handleEvent)

for

.hover(handleEvent)
Comments