Causes the element to receive the focus and executes the code specified by the onfocus event.
![]() |
Syntax
object.focus()Parameters
This method has no parameters.
Return value
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Standards information
- Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
Remarks
This method raises the onfocus event. The effect depends on the object calling the method. When called for child windows (such as those created with the open method of a window object), focus brings the target window to the foreground.
Elements cannot receive focus until the document finishes loading.
Windows Internet Explorer 8 and later. The focus method no longer brings child windows (such as those created with the open method) to the foreground. Child windows now request focus from the user, usually by flashing the title bar. To directly bring the window to the foreground, add script to the child window that calls the focus method of its window object.
Windows Internet Explorer 7 and later. For security reasons, child windows will only respond to the focus method when the following conditions are true:
- The child window does not have multiple tabs open.
- The focus method was not triggered by a double-click action.
If any of these conditions are true, the child window ignores the focus event.
As of Microsoft Internet Explorer 5, elements that expose the focus method must have the tabIndex attribute set.
See also
- a
- abbr
- acronym
- address
- applet
- area
- b
- bdo
- big
- blockQuote
- body
- button
- caption
- center
- cite
- custom
- dd
- del
- dfn
- dir
- dl
- document
- dt
- em
- embed
- fieldSet
- font
- form
- frame
- frameSet
- hn
- hr
- i
- iframe
- img
- input type=button
- input type=checkbox
- input type=file
- input type=image
- input type=password
- input type=radio
- input type=reset
- input type=submit
- input type=text
- ins
- isIndex
- kbd
- label
- legend
- li
- listing
- marquee
- menu
- object
- ol
- p
- plainText
- pre
- q
- rt
- ruby
- s
- samp
- select
- small
- span
- strike
- strong
- sub
- sup
- table
- tBody
- td
- textArea
- tFoot
- th
- tHead
- tr
- tt
- u
- ul
- var
- window
- xmp
Send comments about this topic to Microsoft
Build date: 11/28/2012
