Solved

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

Posted on 2013-01-23
2
362 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
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)

803 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