-
Notifications
You must be signed in to change notification settings - Fork 0
setFocusOnTarget
Mike Byrne edited this page Mar 14, 2023
·
3 revisions
Sets focus on a node
- nothing
- node - required - DOM node to focus
- exact - boolean - defaults to true - focus the exact mode, or focus the first focusable element within the target element
- nothing
var button = document.querySelector('button');
setFocusOnTarget(button); // the button will be focused
var h1 = document.querySelector('h1');
setFocusOnTarget(h1); // the h1 will be focused
...
<div id="modal">
<button id="modalClose">Close Modal</button>
...
</div>
...
var modal = document.querySelector('div#modal');
setFocusOnTarget(modal, false); // the button #modalClose will be focused
// if there is no focusable element inside the target, the target itself is focussed