<span data-href="https://mozilla.org" tabindex="0" role="link">
Fake accessible link created using a span
</span>ARIA: link role / notebook
ARIA: link role
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
span[role="link"] {
color: blue;
text-decoration: underline;
cursor: pointer;
}
span[role="link"]:hover,
span[role="link"]:active,
span[role="link"]:focus {
color: purple;
}
span[role="link"]:focus {
background-color: palegoldenrod;
outline: 1px dotted;
}const fakeLinks = document.querySelectorAll('[role="link"]');
for (const link of fakeLinks) {
link.addEventListener("click", navigateLink);
link.addEventListener("keydown", navigateLink);
}
// handles click and keydown events on the link
function navigateLink(e) {
if (e.type === "click" || e.key === "Enter") {
const ref = e.target ?? e.srcElement;
if (ref) {
window.open(ref.getAttribute("data-href"), "_blank");
}
}
}