Answer the question
In order to leave comments, you need to log in
What to use instead of href="#"?
Often, controls are rendered using the HTML tag a
.
This provides several benefits:
click
on pressing Enter when the link is in focuspreventDefault
span
with the attribute tabindex="0"
. But the event click
on pressing Enter will not work. Let's go ahead and replace the tag with button
. Now everything is almost perfect. Except that this tag is the hardest to style, especially when using global styles. Answer the question
In order to leave comments, you need to log in
I wrote a short article on which you can choose what to use, and what is better to refuse. How not to use a(href="#")
You can remove the link attribute and business then. Who prevents to write I button . In general, this is nonsense. There is no need to change the semantics to smart-ass things of incomprehensible content. The link should remain a link, if it's an empty control then just take the span.
You can do href="" - it behaves like a regular link, when you hover it shows the address of the current page. But you still have to add preventDefault.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question