Guest User

Untitled

a guest
Dec 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <html>
  2. <head></head>
  3. <body>
  4. <ul id="todo-app">
  5. <li class="todo">Walk the dog</li>
  6. <li class="todo">Pay bills</li>
  7. <li class="todo">Make dinner</li>
  8. <li class="todo">Code for one hour</li>
  9. </ul>
  10.  
  11. <!-- Move script tag below app so we don't have to use setTimeout -->
  12. <script>
  13. // Use more diliberate selector so we don't have to type check
  14. const app = document.getElementById('todo-app');
  15. const todos = app.querySelectorAll('.todo');
  16.  
  17. // Use foreach for cleaner looping of todos
  18. todos.forEach((todo, i) => {
  19. todo.addEventListener(
  20. 'click',
  21. ({ target }) => {
  22. // Use object destructuring for cleaner variable refereneces
  23.  
  24. // Set only text-decoration styling instead of replacing entire style object
  25. todo.style.textDecoration = 'line-through';
  26.  
  27. // Use string literal for cleaner string concatination
  28. alert(`Item ${i + 1}: "${target.innerText}" is done!`);
  29. }
  30. );
  31. });
  32. </script>
  33. </body>
  34. </html>
Add Comment
Please, Sign In to add comment