Remember last focus
// Store the last focused element
let
lastFocusedElement
=
document
.
activeElement
;
//
Set focus to the modal window
modal
.
focus
();
// Close the window by clicking the close button
close
.
addEventListener
(
'click'
,
removeModal
);
function
removeModal
() {
// Remove the modal window if it's visible
modal
.
classList
.
remove
(
'is-visible'
);
// Return focus to last focused element
lastFocusedElement
.
focus
();
}