Prevent tabstop on A element (anchor link) in HTML

Is it possible to cancel an <a href="..."> from being tabstopped in any browser? I would like to do this without Javascript.

13.10.2009 15:34:43
5 ОТВЕТОВ
РЕШЕНИЕ

Some browsers support the tabindex="-1" attribute, but not all of them, since this is not a standard behaviour.

262
12.02.2016 14:43:08
Oh great! Thanks! I've checked with FF3.5, IE8 and CH3 and it work in all three. Thanks a million!
Robert Koritnik 13.10.2009 16:40:16
No worries about this: just like zzzzBov states here, HTML5 came to the rescue and standardized this functionality. So now the guilty browsers are those that miss this.
TechNyquist 17.11.2017 08:52:21
Keep in mind that disabling the tabstop on a hyperlink goes against accessibility rules (e.g. people using screen readers, etc). If you know that this isn't a problem for your user base, then it should be fine.
Ricardo Sanchez 29.03.2018 00:27:32

I think you could do this by javascript, you override the window.onkeypress or onkeydown, trap the tab button, and set the focus at the desired order.

6
24.11.2011 21:05:37
I don't know whether you've checked other answers especially accepted one that was answered about a year ago and solved this problem without using Javascript.
Robert Koritnik 30.09.2010 16:44:22
I appreciate the alternative solution even if it doesn't address the OP as well as the accepted answer. No need to be disparaging.
Anthony DiSanti 1.11.2010 18:45:32
@Anthony DiSanti: That is true, but in this particular case I still dn't see why would one resort to javascript if something else works better? So if it's not an answer to this question why is it here then? Nevermind. Javascript is usually the last step one would take if certain things can't be done otherwise. And I'm sorry @Ammosi if I've insulted you. I didn't mean to be rude. Thanks for the late answer.
Robert Koritnik 11.02.2011 08:35:17
I agree with avoiding javascript if there is a standards-based HTML or CSS solution. However, in this case there is not. The original poster didn't need to support browsers prior to IE8 and FF3.5, but for my work I need to support back to IE6. The tabindex solution is therefore not applicable. Providing the only working solution in the browser with the greatest market share should not be discouraged.
Anthony DiSanti 12.02.2011 19:47:01

Modern, HTML5 compliant, browsers support the [tabindex] attribute, where a value of -1 will prevent the element from being tabbed to.

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

73
26.08.2012 06:30:45
Documentation excerpts always help. ;-) This tells us that those not supporting this are among the few and they'll likely support it sooner or later.
Robert Koritnik 4.06.2014 18:58:19

You could apply a JQuery handler to the element you want to target multiple elements with no tab stop.

$(document).ready(function () {
    $('.class').attr('tabindex', '-1');
});

Would be one way to do it....

15
13.02.2013 10:39:34

Remove the href attribute from your anchor tag

4
27.02.2018 12:01:14
what if I can not?
Hakan Fıstık 27.02.2018 12:02:00
If willing to use javascript despite the question to avoid that kind of solutions, to remove href attributes, use jquery document onload with something like $('[href="whatever-the-url-is"]').removeAttr('href');
Jonas Lundman 6.06.2018 22:45:46
LOL remove the href
quemeful 9.10.2018 12:25:42