HTML DOM Element focus() method
- Föregående sida firstElementChild
- Nästa sida getAttribute()
- Åter till föregående nivå HTML DOM Elements objekt
Definition and usage
focus()
Methods to make an element obtain 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 web browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Stöd | 9-11 | Stöd | Stöd | Stöd | Stöd |
- Föregående sida firstElementChild
- Nästa sida getAttribute()
- Åter till föregående nivå HTML DOM Elements objekt