HTML DOM Element focus() method
- Previous page firstElementChild
- Next page getAttribute()
- Go back to the previous level HTML DOM Elements object
Definition and usage
focus()
Method to let an element 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 back to the previous level HTML DOM Elements object