Bybnovskiy Bybnovskiy - 4 months ago 46
Javascript Question

SetInterval for hover event

I have input field here, when I hover on input field asterisk adds, when I lose hover input text is clean. How with setInterval(maybe) I can add additional asterisk in input field every second when it's hovered?

$('body').append("<input type='text' />");

$('input').hover(function() {
$(this).val('*' + $(this).val());
$('input').mouseleave(function() {


Replace this:

$(this).val('*' + $(this).val());


setInterval(function(){ $("#input").val($("#input").val() + "*") }, 1000);

That should do the trick