Bybnovskiy Bybnovskiy - 1 month ago 8
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() {
$(this).val('');
})

Answer

Replace this:

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

With

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

That should do the trick