How to detect that the spacebar has been pressed on an element using Javascript?

I would like to do the following. I have a link and for accessibility, I want that when I hover over the link (using the keyboard tab) and press the space bar, then launch a Javascript behavior.

The link does not go to any site, it only allows the user to stop on it, pressing the tabulator.

Link

In addition, I also wish that, if you click on the link, you will not go anywhere. That’s clear to me

document.getElementById(“ellink”).addEventListener(‘click’, function(e) { e.preventDefault(); });

I think I’d have to add keyboard events, but I don’t really know how to detect that the spacebar has been specifically pressed.

See also  /faq/278.php
Loading Facebook Comments ...
Loading Disqus Comments ...