Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const myButton = document.createElement('button');
- var buttonText = 0;
- myButton.innerHTML = buttonText;
- myButton.id = "button";
- myButton.style.width = "96px";
- myButton.style.height = "48px";
- myButton.style.fontSize = "24px";
- const body = document.querySelector('body');
- body.appendChild(myButton);
- document.addEventListener('click', function(event){
- // If the clicked element doesn't have the right selector, bail
- if (!event.target.matches('#button')) return;
- // Don't follow the link
- event.preventDefault();
- buttonText++;
- myButton.innerHTML = buttonText;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement