Skip to content
Advertisement

How can I delay something in JavaScript [closed]

I wanted to set a delay on this script but I don’t know how it works. So I would like to ask if someone can help me with a Solution for this/

const el = document.getElementById("search-label");
el.addEventListener("keydown", function(event) {
    
    if(event.key === "Enter") {
      el.blur();
  }

});

Advertisement

Answer

const el = document.getElementById("search-label");
el.addEventListener("keydown", function(event) {
    if(event.key === "Enter") {
        setTimeout(function(){  
             el.blur();
        }, 5000);
  }
});
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement