Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.05 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Lista</title>
  5.   </head>
  6.   <script>
  7.     window.onload = () =>
  8.       document
  9.         .getElementsByTagName("form")[0]
  10.         .addEventListener("submit", event => submitHandler(event));
  11.  
  12.     function submitHandler(event) {
  13.       event.preventDefault();
  14.       addBullet();
  15.       document.getElementById("user-todo").value = "";
  16.     }
  17.  
  18.     function clearList() {
  19.       document.getElementById("items").innerHTML = "";
  20.     }
  21.  
  22.     function addBullet() {
  23.       let value = document.getElementById("user-todo").value;
  24.       let bullet = document.createElement("li");
  25.       bullet.appendChild(document.createTextNode(value));
  26.  
  27.       document.getElementById("items").appendChild(bullet);
  28.     }
  29.   </script>
  30.   <body>
  31.     <h1 id="title">Lista</h1>
  32.     <form>
  33.       <input type="text" id="user-todo" placeholder="Lista" required />
  34.     </form>
  35.     <h2 id="todo-header">Rzeczy:</h2>
  36.     <ul id="items"></ul>
  37.     <button id="clear" onclick="clearList()">Reset</button>
  38.     <script></script>
  39.   </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement