Bybnovskiy Bybnovskiy - 1 year ago 142
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() {

Answer Source

Replace this:

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


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

That should do the trick

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download