Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A button can be identified using JavaScript by giving it an ID attribute and then using the document.getElementById() method to access it. For example:

HTML: <button id="myButton">Click me</button>

JavaScript: var button = document.getElementById("myButton"); button.addEventListener("click", function() { alert("Button clicked!"); });

In this example, the button is identified using the ID "myButton" and the click event is added using the addEventListener() method.