This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
…if you’re adding an event listener to an <a>
with “#” as the value of the href
attribute, the element you're actually looking for is <button>
.
<a href="#" onclick="doSomething()">
Show results
</a>
More accessible alternative:
<button onclick="doSomething()">
Show results
</button>
Explanation
The role of <a>
is link and the role of <button>
is button. Users have certain expectations when they find an element. A general rule of thumb: Use a link if it takes you somewhere else. Use a button if you submit a form or run JavaScript.
My blog doesn't support comments yet, but you can reply via blog@matuzo.at.
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2023-04-18T09:46:54+00:00) click event on a. Retrieved from https://www.scien.cx/2023/04/18/click-event-on-a/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.