ally.get.focusTarget

September 28, 2016 ยท View on GitHub

Identifies the element that would get focus upon click

Description

When clicking on the <span> element, focus is given to the <div>, because it's the first focusable parent element.

<div tabindex="-1">
  <p>Hello <span>World</span>!</p>
</div>

When clicking on the <label> element, focus is given to the <input>, because it's the referenced form control.

<label for="world">Hello</label>
<input id="world" type="text">

Usage

var element = ally.get.focusTarget({
  context: '#element-to-start-from',
});

Arguments

NameTypeDefaultDescription
context<selector>requiredThe element to start searching from. The first element of a collection is used.
except<focus identification exception>{}The Element to test.

Returns

HTMLElement.

Throws

TypeError if context option is not specified.

Examples

Changes

  • Since v1.1.0 elements redirecting focus return their target elements.
  • Since v1.1.0 exceptions can be passed through to ally.is.focusable via the except argument.

Notes

See ally.get.focusRedirectTarget

Contributing