Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created June 14, 2023 13:55
Show Gist options
  • Save nocodesupplyco/86be1f32ab3a56bf97fc929f4fda02a4 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/86be1f32ab3a56bf97fc929f4fda02a4 to your computer and use it in GitHub Desktop.
Skip Nav to Main Function
window.addEventListener("DOMContentLoaded", (event) => {
let skipLinkEle = document.getElementById("skip-link");
if (!skipLinkEle) {
return;
}
skipLinkEle.addEventListener("click keydown", function (e) {
if (e.type === "keydown" && e.which !== 13) {
return;
}
e.preventDefault();
var target = document.getElementById("main");
target.setAttribute("tabindex", "-1");
target.focus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment