I was wondering, can you make an element that is not an anchor (<a>
) tag (for ex. <div>
, <span>
, etc.) behave like an anchor tag? (Link to page on click).
Or, are there any other elements that behave the same?
Only partially.
tabindex
to make it focusable.click
event listener that sets location.href
.:link
and :visited
in CSSThat leaves aside issues of getting (for example) screen readers to recognise the element as a link and annouce it to the user, and for search engines to recognize it as a link and follow it, and the JS simply failing.
In short: If you want a link, then use a real link. HTML is a semantic markup language. Use the semantics it comes with. Don't try to fake the behaviour that comes with the semantics using other elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With