Skip to content

ally.js

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

🔗ally.get.focusTarget

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.

🔗Returns

HTMLElement.

🔗Throws

TypeError if context option is not specified.

🔗Changes

🔗Notes

See ally.get.focusRedirectTarget

🔗Contributing