Skip to content

ally.js

JavaScript library to help modern web applications with accessibility concerns by making accessibility simpler

# 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.

# Changes

# Notes

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

# Contributing