You can add a click event handler for this:
document.getElementById('button').onclick = function() { alert("button was clicked"); };
This will alert when it’s clicked, if you want to track it for later, just set a variable to true in that function instead of alerting, or variable++
if you want to count the number of clicks, whatever your ultimate use is. You can see an example here.
Related Posts:
- Wait 5 seconds before executing next line
- window.onload vs document.onload
- JavaScript: SyntaxError: missing ) after argument list
- jQuery.click() vs onClick
- What is event bubbling and capturing?
- How to make JavaScript execute after page load?
- jQuery equivalent of JavaScript’s addEventListener method
- What is DOM Event delegation?
- Onclick javascript to make browser go back to previous page?
- How to make JavaScript execute after page load?
- Adding an onclick event to a div element
- Scroll to the top of the page using JavaScript?
- Generate pdf from HTML in div using Javascript
- iFrame onload JavaScript event
- How to terminate the script in JavaScript?
- Fire ontextchanged() event of an asp:TextBox via Javascript
- Get selected value in dropdown list using JavaScript
- Clearing localStorage in javascript?
- How do you Hover in ReactJS? – onMouseLeave not registered during fast hover over
- How to make JavaScript execute after page load?
- How to remove all listeners in an element?
- How to ‘minify’ Javascript code
- ++someVariable vs. someVariable++ in JavaScript
- Get a random item from a JavaScript array
- JavaScript: IIF like statement
- Is it possible to append to innerHTML without destroying descendants’ event listeners?
- Is it possible to simulate key press events programmatically?
- Getting DOM element value using pure JavaScript
- How do I select text nodes with jQuery?
- window.onload vs $(document).ready()
- How to get scrollbar position with Javascript?
- Empty functions in Javascript
- Why onbeforeunload event is not firing
- How to make HTML element resizable using pure Javascript?
- window.location.href doesn’t redirect
- How can I capture the right-click event in JavaScript?
- How can I generate a rainbow circle using HTML5 canvas?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Using prevNext Modx Addon
- How to convert decimal to hexadecimal in JavaScript
- What does “javascript:void(0)” mean?
- :wq! command in vim
- how to set the background color of the status bar during the launching phase [duplicate]
- For-each over an array in JavaScript
- api-ms-win-crt-runtime-l1-1-0.dll is missing when opening Microsoft Office file [closed]
- How to delete a cookie?
- When is K 1024 and when is it 1000?
- What is a MIME type?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How do you use the ? : (conditional) operator in JavaScript?
- How do you use the ? : (conditional) operator in JavaScript?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- Generate unique random numbers between 1 and 100
- Logitech/LGHUB Lua – Loop with break
- are there dictionaries in javascript like python?
- are there dictionaries in javascript like python?
- How can I convert MP3 file to a Base64 encoded string? [closed]
- Understanding The Modulus Operator %
- How to do associative array/hashing in JavaScript
- How to append something to an array?
- How to format a JavaScript date
- Understanding the main method of python [duplicate]
- Dial pad to get phone number (with Android button images)
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How is the AND/OR operator represented as in Regular Expressions?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to make a discord bot create an invite for every server it joins?
- Istio Ingress resulting in “no healthy upstream”
- How to prevent the “Confirm Form Resubmission” dialog?
- Why is it not possible to fake an IP address?
- How to open a “-” dashed filename using terminal?
- Substring in excel
- ES6 Map in Typescript
- What is a LAMP stack?
- What is a sanity test/check
- What is the difference between POST and PUT in HTTP?
- addEventListener vs onclick
- What is the difference between POST and PUT in HTTP?
- Sorting an array of objects by property values
- How to find Google’s IP address?
- What is the JavaScript version of sleep()?
- What exactly is a VBO in OpenGL?
- What and where are the stack and heap?
- ping response “Request timed out.” vs “Destination Host unreachable”
- Authentication versus Authorization
- What is a reverse shell?
- How does npm start work? What all processes are happening in the background?
- What is an instance variable in Java?
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- What is the := operator?
- How to re-enable right click so that I can inspect HTML elements in Chrome?
- What is tail recursion?
- How do I check if an array includes a value in JavaScript?
- Discord music bot not working
- What does “:=” mean in Pseudocode? [closed]
- JavaScript document.getElementById().value logs empty value
- How do I color a hexagonal grid such that it doesn’t have neighbors of the same color?
- How to format a JavaScript date
- Why am I getting error for apple-touch-icon-precomposed.png
- enabling right click: