Skip to content

Instantly share code, notes, and snippets.

@marta-krzyk-dev
Created May 6, 2020 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marta-krzyk-dev/178fb41858538efd825c0a92d4723515 to your computer and use it in GitHub Desktop.
Save marta-krzyk-dev/178fb41858538efd825c0a92d4723515 to your computer and use it in GitHub Desktop.
ClearTimer pattern in JS6
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);
}
<!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