Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let cross = document.getElementById("button1");
  2.         let input = document.getElementById("szukaj");
  3.         let isCrossShown = false;
  4.  
  5.         function showBtn() {
  6.             if (input.value=="") {
  7.                 cross.style.display = "none";
  8.             }
  9.            
  10.             else {
  11.             cross.style.display = "inline-block";
  12.             isCrossShown = true;
  13.             }
  14.         }
  15.  
  16.         input.addEventListener("change", showBtn);
  17.         input.addEventListener("keyup", showBtn);
  18.         input.addEventListener("keydown", showBtn);
  19.  
  20.         function removeText() {
  21.             if (isCrossShown == true) {
  22.                 input.value = "";
  23.                 isCrossShown = false;
  24.                 cross.style.display = "none";
  25.             }
  26.         }
  27.  
  28.         cross.addEventListener("click", removeText);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement