Solved

left mouse click e.which==1 works on FF18 but not IE7

Posted on 2013-01-23
2
358 Views
Last Modified: 2013-01-24
The below code works for both ctrl-click and left-click in Firefox but only the ctrl-click is recognised in IE7:

$('#tsTable').on('click', 'span.debtor', function(e) {
  if(e.ctrlKey) {
    alert('ctrl-click!');
  } else if(e.which==1) {
    alert('left click!');
  }
  return false;
});

What do I need to change to make IE recognise the left-click (without the ctrl key)?
0
Comment
Question by:ShanghaiD
2 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 500 total points
ID: 38813258
Use this code:

$('#element').mousedown(function(event) {
    switch (event.which) {
        case 1:
            alert('Left mouse button pressed');
            break;
        case 2:
            alert('Middle mouse button pressed');
            break;
        case 3:
            alert('Right mouse button pressed');
            break;
        default:
            alert('You have a strange mouse');
    }
});

Open in new window


Reference:

http://jsfiddle.net/tkbzg/
0
 

Author Closing Comment

by:ShanghaiD
ID: 38816957
Thank you -- "mousedown", not "click" works!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now