Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-23
2
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 2000 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

722 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