Advertisement
Guest User

Untitled

a guest
Sep 12th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const myButton = document.createElement('button');
  2. var buttonText = 0;
  3. myButton.innerHTML = buttonText;
  4. myButton.id = "button";
  5. myButton.style.width = "96px";
  6. myButton.style.height = "48px";
  7. myButton.style.fontSize = "24px";
  8.  
  9. const body = document.querySelector('body');
  10. body.appendChild(myButton);
  11.  
  12.  
  13. document.addEventListener('click', function(event){
  14. // If the clicked element doesn't have the right selector, bail
  15. if (!event.target.matches('#button')) return;
  16.  
  17. // Don't follow the link
  18. event.preventDefault();
  19. buttonText++;
  20. myButton.innerHTML = buttonText;
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement