Thursday, October 5, 2023
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  40] [ 6]  / answers: 1 / hits: 23638  / 15 Years ago, mon, april 6, 2009, 12:00:00

How can I write an onclick handler that does one thing for regular clicks and a different thing for shift-clicks?


More From » javascript

 Answers
30

You can look at the click event's shiftKey property.





window.addEventListener(click,
function(e) {
if (e.shiftKey) console.log(Shift, yay!);
},
false);

<p>Click in here somewhere, then shift-click.</p>




[#99738] Wednesday, April 1, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zackeryzainv

Total Points: 61
Total Questions: 102
Total Answers: 99

Location: Andorra
Member since Sat, May 27, 2023
5 Months ago
;