blob: 62a186e97c23a55a49c68db47ba5908d3c5cef04 (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
---
title: blur (evento)
slug: Web/API/Element/blur_event
tags:
- DOM
translation_of: Web/API/Element/blur_event
original_slug: Web/Events/blur
---
<p>El evento <code>blur</code> es disparado cuando un elemento ha perdido su foco. La diferencia principal entre este evento y <code><a href="/en-US/docs/Mozilla_event_reference/focusout">focusout</a></code> es que sólo el último se propaga (bubbles).</p>
<h2 id="Información_General">Información General</h2>
<dl>
<dt style="float: left; text-align: right; width: 120px;">Especificación</dt>
<dd style="margin: 0 0 0 120px;"><a class="external" href="http://www.w3.org/TR/DOM-Level-3-Events/#event-type-blur">DOM L3</a></dd>
<dt style="float: left; text-align: right; width: 120px;">Interfaz</dt>
<dd style="margin: 0 0 0 120px;">{{domxref("FocusEvent")}}</dd>
<dt style="float: left; text-align: right; width: 120px;">Burbujas</dt>
<dd style="margin: 0 0 0 120px;">No</dd>
<dt style="float: left; text-align: right; width: 120px;">Cancelable</dt>
<dd style="margin: 0 0 0 120px;">No</dd>
<dt style="float: left; text-align: right; width: 120px;">Objetivo</dt>
<dd style="margin: 0 0 0 120px;">Element</dd>
<dt style="float: left; text-align: right; width: 120px;">Acción por defecto</dt>
<dd style="margin: 0 0 0 120px;">Ninguna.</dd>
</dl>
<p>{{NoteStart}}El valor de {{domxref("Document.activeElement")}} varía a traves de navegadores mientras este evento está siendo manejado ({{bug(452307)}}): IE10 lo agrega al elemento al cual el foco se movera, mientras Firefox y Chrome muy seguido lo agregan al cuerpo del documento.{{NoteEnd}}</p>
<h2 id="Propiedades">Propiedades</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Propiedad</th>
<th scope="col">Tipo</th>
<th scope="col">Descripción</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>target</code> {{readonlyInline}}</td>
<td>{{domxref("EventTarget")}}</td>
<td>Objetivo del evento (elemento DOM)</td>
</tr>
<tr>
<td><code>type</code> {{readonlyInline}}</td>
<td>{{domxref("DOMString")}}</td>
<td>El tipo de evento.</td>
</tr>
<tr>
<td><code>bubbles</code> {{readonlyInline}}</td>
<td>{{jsxref("Boolean")}}</td>
<td>Si el elemento normalmente se propaga o no.</td>
</tr>
<tr>
<td><code>cancelable</code> {{readonlyInline}}</td>
<td>{{jsxref("Boolean")}}</td>
<td>Si el evento es cancelable o no.</td>
</tr>
<tr>
<td><code>relatedTarget</code> {{readonlyInline}}</td>
<td>{{domxref("EventTarget")}} (DOM element)</td>
<td>null</td>
</tr>
</tbody>
</table>
<h2 id="Delegación_de_eventos">Delegación de eventos</h2>
<p>Hay dos maneras de implementar la delegación de eventos para este evento: usando el evento <code>focusout</code> en exploradores que lo soporten, o cambiando el parámetro "useCapture" de <a href="/en-US/docs/DOM/element.addEventListener"><code>addEventListener</code></a> a <code>true</code>:</p>
<h3 id="Contenido_HTML">Contenido HTML</h3>
<pre class="brush:html;"><form id="form">
<input type="text" placeholder="text input">
<input type="password" placeholder="password">
</form></pre>
<h3 id="Contenido_JavaScript">Contenido JavaScript</h3>
<pre class="brush: js">var form = document.getElementById("form");
form.addEventListener("focus", function( event ) {
event.target.style.background = "pink";
}, true);
form.addEventListener("blur", function( event ) {
event.target.style.background = "";
}, true);</pre>
<p>{{EmbedLiveSample('Delegación_de_eventos')}}</p>
<h2 id="Compatibilidad_en_navegadores">Compatibilidad en navegadores</h2>
{{Compat("api.Element.blur_event")}}
<h2 id="Eventos_relacionados">Eventos relacionados</h2>
<ul>
<li>{{event("focus")}}</li>
<li>{{event("blur")}}</li>
<li>{{event("focusin")}}</li>
<li>{{event("focusout")}}</li>
</ul>
|