Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable tab key on a specific div

I have the following structure:

<div id="wrapper">
   <div id="div1">Some content</div>
   <div id="div2">Some content</div>
</div>

I want to "disable" the tab key on div2, I mean the elements of div2 won't receive focus when the tab key is pressed.

Is there any easy way to create this tab key blocker using javascript/jquery?

like image 998
nepomucenobr Avatar asked Apr 05 '11 18:04

nepomucenobr


People also ask

How do I remove a Tabindex attribute?

The task: to get rid of all tabindex with -1 value, add type="tex/javascript" for all script tags, type="text/css" for style tags and out an alt to all img tags. These are all for the sake of html validation.

What does Tabindex =- 1 mean?

A negative value (usually tabindex="-1" ) means that the element is not reachable via sequential keyboard navigation, but could be focused with JavaScript or visually by clicking with the mouse. It's mostly useful to create accessible widgets with JavaScript.

Can I set Tabindex with CSS?

Yes. It is useful. The most useful values are tabindex="0" for example on <span/> or <div/> element and tabindex="-1" to disable tab stops or make elements focusable without tab-navigation. I created HTML+CSS libraries that use this.


1 Answers

@John Strickler is right. The behaviour of the tab key can be changed with the tabindex attribute. It is the order the elements will have the focus.

With <div id="div1" tabindex="-1">Some content</div> you should prevent the focus to be on your div.

More info here: http://www.htmlcodetutorial.com/forms/_INPUT_TABINDEX.html

like image 93
Jason Avatar answered Sep 19 '22 23:09

Jason