Is it possible to use <a> (anchor tag) without href attribute?


Zachary

I've been building websites with Twitter Bootstrap, and many of its features rely on wrapping content in <a>, even if they're just executing Javascript. I'm having trouble with the strategy href="#"suggested by the Bootstrap documentation , so I'm trying to find other solutions.

But then I tried to remove the hrefattribute completely. I've been using <a class='bunch of classes' data-whatever='data'>that and let Javascript handle the rest. And it works.

But something tells me I shouldn't do it. right? I mean, it should technically <a>be a link to something, but I'm not sure why this is an issue. still is?

zzzzBov

The nchor <a>element is just an anchor, or from some content. Originally, the HTML specification allowed the use of named anchors ( <a name="foo">) and link anchors ( <a href="#foo">).

The named anchor format is less commonly used because fragment identifiers are now used to specify [id]properties (although for backward compatibility you can still specify [name]properties). Elements without attributes still work .<a>[href]

In terms of semantics and style, an <a>element is not a link ( ) unless it :linkhas an [href]attribute . The side effect of this is that by default, elements <a>that don't will not [href]be in tab-sorted order.

The real question is whether the <a>element itself is an appropriate representation <button>. At the semantic level, there is a clear distinction between a linkand a button.

A button is what causes an action to happen when clicked.

A link is a button that causes the navigation in the current document to change. If it is a fragment identifier ( #foo) , the navigation that occurs may be moving within the document ; if it is a URL ( /bar) , the navigation that occurs may be moving to a new document .

Because links are a special type of button, their actions are often rewritten to perform other functions. Continuing to use anchors for buttons is fine from a consistency standpoint, although not quite semantically accurate yet.

If you are concerned about the semantics and accessibility of using an <a>element (or <span>, or <div>) as a button , you should add the following attributes:

<a role="button" tabindex="0" ...>...</a>

The button's action tells the user that this particular element is to be treated as a button as the underlying element for any semantics may have an overlay for that user.

For <span>and <div>elements, you may want to add JavaScript key listeners Spaceor Enterfire the clickevent. <a href>and <button>elements do this by default, but non-button elements do not. Sometimes it makes more sense to bind clicktriggers to other keys . For example, a "Help" button in a web application might be bound to F1.

Related


Is it possible to use <a> (anchor tag) without href attribute?

Zachary I've been building websites with Twitter Bootstrap, and many of its features rely on wrapping content in <a>, even if they're just executing Javascript. I'm having trouble with the strategy href="#"suggested by the Bootstrap documentation , so I'm tryi

Is it possible to use <a> (anchor tag) without href attribute?

Zachary I've been building websites with Twitter Bootstrap, and many of its features rely on wrapping content in <a>, even if they're just executing Javascript. I'm having trouble with the strategy href="#"suggested by the Bootstrap documentation , so I'm tryi

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

Safari anchor tag with href attribute not getting focus?

men I had this problem, and I thought my code was wrong, but after googling around and looking at related examples, I wonder if Safari really doesn't focus tabs <a>on properties href? In my use case I want <a href="#top">jump</a>to use to jump to page section.

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to focus on anchor tag without href="#"

username How to focus when using keyboard tabs? <a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click" title="Prev"><span class="ui-icon ui-icon-circle-triangle-w">Prev</span></a> I try to use CSS like this ui-datepicker-prev:focus

How to use querySelector with anchor tag with href?

User 3242861 I'm trying to use dropzone and I have an anchor tag to which I need to add an event click, but the way I'm doing this returns an error. URL: <a href="#new-intervention">Criar Intervenção</a> Inquire: var myDropzone = this; this.element.querySele