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>
without an href
attribute, the element you're actually looking for is <button>
.
<a onclick="doSomething()">
Show results
</a>
More accessible alternative:
<button onclick="doSomething()">
Show results
</button>
Explanation
If the <a>
element has no href
attribute, then the element represents a placeholder for where a link might otherwise have been placed. That's neither a regular hyperlink nor a button. 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-20T09:46:54+00:00) placeholder link. Retrieved from https://www.scien.cx/2023/04/20/placeholder-link/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.