HTML DOM focus()Method
Definition and Usage
The focus() method is used to set focus to an element (if it can be set).
Tip:Useblur()the method to remove element focus.
Browser Support
| Method | |||||
|---|---|---|---|---|---|
| focus() | Yes | Yes | Yes | Yes | Yes |
Syntax
HTMLElementObject.focus()
Parameters
| None |
Technical Details
| Return Value: | No return value |
|---|
More Examples
Example
Set focus to a text field after the document has loaded:
window.onload = function() {
document.getElementById("myText").focus();
};
document.getElementById("myText").focus();
};
Try it Yourself »
Related Pages
HTML DOM Reference:onfocus Event
Other Extensions
Element Object