Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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…

896 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

11 Experts available now in Live!

Get 1:1 Help Now