Forum Moderators: open

Message Too Old, No Replies

focus()

Working in IE but not firefox

         

gosman

3:57 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



I have the following code.

<input type="button" value="Dis" onclick="getElementById('Hid').style.visibility='visible';getElementById('Hid').focus()">

In IE it works as expected by displaying a hidden div and then setting focus to that div, however in Firefox the div is displayed but focus is not set.

Any suggestions?

Fotiman

4:15 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



According to the DOM Specification [w3.org], the only elements that can receive focus are HTMLSelectElement [w3.org], HTMLInputElement [w3.org], HTMLTextAreaElement [w3.org], and HTMLAnchorElement [w3.org]

DIV elements are not included. You might be able to scroll to the element though, or perhaps set the location to the current URL + "#Hid".

gosman

4:44 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



Thank you Fotiman. Sorted it out using an anchor.