Advertisement
MarcHumer

Untitled

Jan 10th, 2021
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="de">
  3. <head>
  4. <title>AB10 Aufgabe 1</title>
  5. <meta charset="utf-8">
  6. <style>
  7. body {
  8. text-align: center;
  9. }
  10.  
  11. .button {
  12. background-color: grey;
  13. width: 80%;
  14. height: 100px;
  15. }
  16. </style>
  17.  
  18. <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  19. </head>
  20. <body>
  21.  
  22. <form>
  23. <button type="button" class="button" id="button0">Tap or Click me</button>
  24. <button type="button" class="button" id="button1">Tap or Click me</button>
  25. <button type="button" class="button" id="button2">Tap or Click me</button>
  26. </form>
  27. <script>
  28.  
  29. const cbox = document.querySelectorAll(".button");
  30.  
  31. for (let i = 0; i < cbox.length; i++) {
  32. cbox[i].addEventListener("click", function() {
  33. cbox[i].style.backgroundColor = "red";
  34. });
  35. cbox[i].addEventListener("touchstart", function() {
  36. cbox[i].style.backgroundColor = "#" + Math.floor(Math.random()*16777215).toString(16);
  37. });
  38. }
  39.  
  40. </script>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement