views:

634

answers:

2

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?

+1  A: 

I'm not sure if you can make an element 'un-focusable', but you can certainly un-focus it at a specific point in time using its blur method:

document.getElementById("myElement").blur();

EDIT:

I think you can make an element 'un-focusable' by defocusing it every time it is focused. You can accomplish this via:

document.getElementById("myElement").onfocus = function() {
    this.blur();
};

...or (using inline Javascript in your HTML):

<div onfocus="this.blur();"></div>

Steve

Steve Harrison
To blur it, it means the focus is already on it, right?How to disable focus to be set on it?
Morgan Cheng
I'm not sure whether it is possible to make an element 'un-focusable'. Sorry for not reading your question carefully!
Steve Harrison
+6  A: 

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");
Mister Lucky