简体   繁体   中英

Remove HTML tag from tab order

In my app's tab loop, the <html> tag occupies a tab stop. I'm looking to remove the <html> tag from the tap loop.

I tried adding tabindex="-1" to the <html> tag, but on IE11 at least, that did not seem to remove the element from the tab loop. I'm close to spinning my own logic using JS to "skip" to the next focusable element if document.activeElement === <html> , but I'm wondering if there's an easier way.

The solution needs to be supported cross the major browsers: IE11, Edge, FF, Chrome, Safari.

Any ideas?

I visited HTML specification for tabindex attribute -> https://html.spec.whatwg.org/#the-tabindex-attribute

Below is the second para:

When the attribute is omitted, the user agent applies defaults. (There is no way to make an element that is being rendered be not focusable at all without disabling it or making it inert.)

As it is clearly mentioned that the only way to make any element not focusable is by making it disable or make it invisible from DOM.

I am still searching and will post an update on this.

Moreover, I also tried to replicate this issue and could not do it on IE.(did not try to replicate on other browser).

Update 1:

I found the difference in tabIndex between HTML4 AND HTML5 :

It is stated that though HTML5 allows adding tabIndex attributes on any element, it may not have any effect. This is applicable to HTML element also. My I know, how do we know if an HTML element is focused?

Well according to my simple research i have found that you can use You can use tabindex="-1" .

The W3C HTML5 specification supports negative tabindex values.

You can use also,which works for most browsers:

element.removeAttribute('tabindex');

I find this way with jquery but i'm not sure about

$('#yourelment').prop('tabIndex', -1);

Please check those link for more details :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM