Skip to content

Latest commit

 

History

History
65 lines (36 loc) · 2.32 KB

blur.md

File metadata and controls

65 lines (36 loc) · 2.32 KB
layout tags
doc-api.html
argument-list

ally.element.blur

Shifts focus away from an element if it currently has focus.

Description

The blur() method is available on all HTMLElement. But this is not necessarily true for SVGElement. Only Blink and WebKit expose the blur() method on SVG elements, Gecko, Trident and Edge do not. This will likely change once SVG 2 is a thing. Until then ally.element.blur() tries to apply HTMLElement.prototoype.blur to SVGElements. This only works for Internet Explorer 9 - 11, as Gecko and Edge actively prevent this.

According to jQuery Bug 9420 calling blur() on the body element may make the browser window lose focus. ally.element.blur() guards against this.

Usage

var element = document.getElementById('victim');
var result = ally.element.blur(element);

Arguments

Name Type Default Description
element <selector> required The Element to blur. First element of the collections is used.

Returns

HTMLElement that received focus (usually document.body) or null if focus could not be shifted.

Throws

TypeError if element argument does not resolve to an HTMLElement.

Examples

Changes

  • Added in v1.3.0.
  • Since v1.4.0 can blur SVG elements in Firefox, Internet Explorer and Edge.

Notes

:::warning Cannot blur SVG and MathML elements when they're not children of an HTML document. :::

Related resources

Contributing