I made a small function that is getting looped when an input is getting focus and stopping the loop when the input is losing focus. Now I would like to know if there is a better way to write this code.
var timer;
function Change () {
if( !$('#eventurl').val() ) {
$("#js-skipbutton").text('overslaan');
console.log(0);
}
else{
$("#js-skipbutton").text('ophalen');
console.log(1);
}
};
$('#eventurl').focus(function() {
timer = setInterval(Change, 200);
});
$('#eventurl').focusout(function() {
clearTimeout(timer);
Change();
});
This code is changing the text to "overslaan" on a span when the input is empty and to "ophalen" when the input is containing text.
var timer
instead ofvar time
? \$\endgroup\$