Unable to set focus in Firefox / Opera

Setting focus on a form element using JavaScript is usually very simple. I cannot get this to work in Firefox 12.0 or Opera 11.

Works in other browsers (Chrome, IE, etc.) and Firefox 3.6.

Simple HTML:

<form action="">
    <input type="radio" id="focusID1" name="sex" value="male" /> Male<br />
    <input type="radio" id="focusID2" name="sex" value="female" /> Female<br />
</form>

Simple Javascript:

var elem = document.getElementById("focusID2");
if (elem != null) {
   elem.focus();
}

Try this for yourself at http://jsfiddle.net/4Ddtv/ .

+5
source share
1 answer

Firefox worked as expected. The problem was with jsfiddle focus and firefox, not highlighting the focused element.

This is not a problem .. User error!

+2
source

All Articles