A tag is used as a button,
There are four ways to stop the event effect when handling JavaScript actions.
<a href="#">
<a href="javascript:;">
<a href="javascript:void(0)">
<a role="button" tabindex="0">
This can be considered in the following order.
- You can use the button tag, directly with the button tag. Recommended
- If you need to use a tag:
<a href="javascript:;" role="button">
- Click a tag before script load will not scroll to the page like href= "#".
javascript:void(0);
same as the effect, but more simple
- Role: Accessibility
- tab focusing possible (by using HREF)
- If you need to delete href property:
<a role="button" tabindex="0">
(cursor chart with CSS control)
- If there is no href on a tag, you can't tab focusing.
- But setting tabindex= "0" will focusable. (In tab order, follow the basic markup order)
- Reference: If focus is forbidden, use ' tabindex= '-1 "
Reference
<a href="#">
Disadvantages
- Not the original purpose of the hash (anchor is the mobile feature location is used)
- Clicking on the words will scroll the bar to the page list. (column: script error before script load)
It is recommended to use the button tag if the tag is handled with JavaScript .#
- It is recommended to use the HTML basic button
<button>, <input type="button" />
<input type="image" />
. Better than using the button role property.
- Https://developer.mozilla.org/ko/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role
A tag to set the HREF method only for button use #
href="javascript:;"
Orhref="javascript:void(0);"
- Two of them are the same. (Stop the default effect of a tag)
- Use JavaScript when you click Process
- Click before script load will not
href="#"
scroll to the same page
void (0)? #
Https://stackoverflow.com/questions/7452341/what-does-void-0-mean
Https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/void
void(0)
Use for Generation undefined
(void is to return undefined each time)
Reason: Undefined will be the override. (though ECMAScript 5 or newer is no problem ...) )
alert(undefined); //alerts "undefined"var undefined = "new value";alert(undefined) // alerts "new value"
- Why is it 0? : Very simple, very idiomatic.
- Many minifiers replace the undefined
void 0
(small dosage, safe)
- Reference: With
void 0
the same meaning
<a role="button" tabindex="0">
Way
http://wit.nts-corp.com/2014/04/14/1297 > "a Tag"
Https://stackoverflow.com/questions/10510191/valid-to-use-a-anchor-tag-without-href-attribute
You need to use a tag + delete href (no destination):
- Delete href Property
- The role property provided on the Wai-aria spec must tell the button
- For focusable Setup
tabindex="0"
- tab order, follow the basic markup sequence.
- You can't tab the focus without href.
"01" A tag is only used as a button to set the HREF method