Created
May 6, 2020 22:08
-
-
Save marta-krzyk-dev/178fb41858538efd825c0a92d4723515 to your computer and use it in GitHub Desktop.
ClearTimer pattern in JS6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const paraText = "User is typing"; | |
let timer; | |
textarea.addEventListener("keyup", addText); | |
textarea.addEventListener("keydown", removeText); | |
function addText(e){ | |
para.innerText = paraText; | |
} | |
function removeText(e){ | |
clearTimeout(timer); | |
timer = setTimeout(() => { | |
para.innerText = ""; | |
}, 1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div id="div3"> | |
<p>User is typing</p> | |
<textarea></textarea> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment