I was just curious to know can a tag like div or h2 or any other tag be a link without using the a tag.
Thanks in advance!
>Solution :
The simplest way is to use onclick="window.location.assign()"
The snippet below addresses styling, tab accessibility, and browser history concerns, but it is invalid by WCAG.
document.querySelector('.link').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
window.location.assign('https://stackoverflow.com/');
}
});
.link {
color: blue;
text-decoration: underline;
}
.link:hover {
color: darkblue;
cursor: pointer;
}
<div tabindex="1" class="link" onclick="window.location.assign('https://stackoverflow.com/');">
Fake Link
</div>