-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
67 lines (43 loc) · 1.02 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "HTMLElement: blur() method"
short-title: blur()
slug: Web/API/HTMLElement/blur
page-type: web-api-instance-method
browser-compat: api.HTMLElement.blur
---
{{APIRef("HTML DOM")}}
The **`HTMLElement.blur()`** method removes keyboard focus from the current element.
## Syntax
```js-nolint
blur()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
### Remove focus from a text input
#### HTML
```html
<input type="text" id="sampleText" value="Sample Text" /> <br /><br />
<button type="button" onclick="focusInput()">Click me to gain focus</button>
```
#### JavaScript
```js
function focusInput() {
const textField = document.getElementById("sampleText");
textField.focus();
// The input will lose focus after 3 seconds
setTimeout(() => {
textField.blur();
}, 3000);
}
```
#### Result
{{ EmbedLiveSample('Remove_focus_from_a_text_input') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("HTMLElement.focus")}}