There is no onclick event or function associated with it.
There probably is, it's just:
Added with JavaScript code, not with markup; and/or
On an ancestor element
Most likely #1.
Re #1: Using onclick
attributes and such is just one way to put an event handler on a button, and it's a way that's best avoided. Instead, you use modern event handling via addEventListener
(or attachEvent
on old IE). This might be using the DOM directly, or via a library like jQuery, MooTools, React, Vue, ...
Example using the DOM directly:
document.querySelector(".my-button").addEventListener("click", function() {
console.log("Click!");
});
<button type="button" class="my-button">Click Me</button>
Re #2: click
events bubble from the element on which the user clicked to that element's ancestor elements, all the way up to the document element (html
). So you can handle that event on an ancestor element, rather than on the button itself. Handling events on an ancestor element is sometimes called "event delegation."
Example:
document.querySelector(".container").addEventListener("click", function(e) {
console.log("Click on '" + e.target.textContent + "'!");
});
<div class="container">
This div contains two buttons. The event handler is on the div, not the buttons.
<div>
<button type="button">One</button>
<button type="button">Two</button>
</div>
</div>