HTML DOM Element focus() method
- Previous Page firstElementChild
- Next Page getAttribute()
- Go to the Previous Level HTML DOM Elements Object
Definition and usage
focus()
Methods that allow an element to gain focus (if it is focusable).
See also:
Example
Example 1
Focus on an element:
document.getElementById("myAnchor").focus();
Example 2
Place the focus on the text field:
document.getElementById("myText").focus();
Example 3
After the document is loaded, place the focus on the text field:
window.onload = function() { document.getElementById("myText").focus(); }
Syntax
element.focus()
Parameter
None.
Return value
None.
Browser support
element.focus()
It is a DOM Level 2 (2001) feature.
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page firstElementChild
- Next Page getAttribute()
- Go to the Previous Level HTML DOM Elements Object