user2953119
user2953119

Reputation:

How to handle CTRL+click in javascript

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.

Upvotes: 0

Views: 140

Answers (2)

Dagan Bog-Computers
Dagan Bog-Computers

Reputation: 608

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.

Upvotes: 0

Sebastien C.
Sebastien C.

Reputation: 4833

<a href="#test" onclick="if(event.ctrlKey) alert('test');">test</a>

Upvotes: 2

Related Questions