While researching how to use onclick, I found an article called “The Bad Practice of href=”#” onclick” so I’ll introduce it.
Methods Using a Tags
Bad Example
Search
If there’s a value in the href attribute of an a element, it will try to reference the href attribute value after executing the onclick attribute content.
Also, if # is included, it will navigate to the top of the page.
Good Example
Search
Also, if you’re going to execute an onclick event handler, this writing style is clean and good:
Search
Method Using span as Alternative
Search
That’s all.
Reference Information
- Re:href="#" onclick の悪習 - to-R (Re: The Bad Practice of href="#" onclick - to-R)
That’s all from the Gemba.