Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a DIV unfocusable?

I met a problem about HTML rendering.

In dir="rtl" document of IE7, when JavaScript tries to set focus to a DIV element(with oElement.focus() method), the rendering turns to mess. The context is very complicated, so I suppose the easiest fix is to make the DIV unfocusable?

Is there any way to make a DIV not be focused?

like image 518
Morgan Cheng Avatar asked Apr 04 '09 01:04

Morgan Cheng


People also ask

How do you make an element Unfocusable?

In order to make an prevent an element from taking focus ("non-focusable"), you need to use Javascript to watch for the focus and prevent the default interaction. In order to prevent an element from being tabbed to, use tabindex=-1 attribute. Adding tabindex=-1 will make any element focusable, even div elements.

How do I turn off div focus?

To disable focus on a specific element, set the tabIndex property on the element to a value of -1 . The tabIndex property can be used to specify that an element cannot be focused using keyboard navigation. Here is the HTML for the examples in this article.

Can div be focused?

Yes - this is possible. In order to do it, you need to assign a tabindex...

How do you make something Tabbable in HTML?

Add the tabindex="0" attribute to each div you want tabbable. Then use CSS pseudo classes :hover and :focus, for example to signify to the app user that the div is in focus and clickable, for example.


2 Answers

The <div> should not be capable of receiving focus unless you have added tabIndex.

If you have added tabIndex, you should remove it by

document.getElementById("yourElement").removeAttribute("tabIndex");
like image 153
Mister Lucky Avatar answered Oct 11 '22 17:10

Mister Lucky


Additionally, If you want to make a focussable element(form input elements etc.) as unfocussable. You can set :

tabIndex = "-1"

document.getElementById("yourElement").setAttribute("tabIndex", "-1");
like image 37
Robin Maben Avatar answered Oct 11 '22 19:10

Robin Maben