Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable tabs for <a> tag

I am using <a> tags for links on a web page. How do I disable the Tab key from selecting either of them?

like image 433
Rakesh Avatar asked Jan 19 '09 09:01

Rakesh


People also ask

How do I make a tab not clickable?

You can use :not() CSS selector with pointer-events: none; to disable click event. Show activity on this post. Simply add this class to the tabs that you want to disable the clicks.

Can I use disabled in a tag?

The <a> tag doesn't have a disabled attribute, that's just for <input> s (and <select> s and <textarea> s). To "disable" a link, you can remove its href attribute, or add a click handler that returns false.


2 Answers

Alternatively you could go for plain HTML solution.

<a href="http://foo.bar" tabindex="-1">inaccessible by tab link</a> 

The HTML5 spec says:

If the value is a negative integer
The user agent must set the element's tabindex focus flag, but should not allow the element to be reached using sequential focus navigation.

like image 108
Sergey Ilinsky Avatar answered Sep 28 '22 04:09

Sergey Ilinsky


I've had to prevent divs with and overflow: auto css rule from having a tab stop before and what I did was (transposed for a's):

var links = document.getElementsByTagName( 'a' );  for( var i = 0, j =  links.length; i < j; i++ ) {     links[i].setAttribute( 'tabindex', '-1' ); } 

Using tabindex rather than blurring means the focus will skip to the next element.

Are you sure you want to disable tabindex though? It's kinda vital for navigation without a mouse.

Just noticed a similar answer in plain HTML

like image 35
meouw Avatar answered Sep 28 '22 05:09

meouw