<a href="#test" onclick="if(event.ctrlKey) alert('test');">test</a>
How to handle CTRL+click in javascript
-
09-07-2023 - |
Question
Let I've the <a href="/link/">
tag. How can I the following handle: When the CTRL
key is pressed we're left clicked to the <a href="/link/">
tag I want to run an appropriate function which I'll specified as handler of this event. How to do that? I want to do this with pure JS.
Solution
OTHER TIPS
I can also recommened the Jquery way.
$('#element').click(function(e)
{
if (e.ctrlKey)
{
do_something();
}
});
May be seems a bit less simple, but I guess it gives you more options aswell.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow