logo

Detect left mouse button click with jQuery

Date: 2010-12-08

This script below will detect left mouse click and pop up an alert when you left click on the link "Click me".

Code:

<script>
$(function(){
$("#click-me").live('click', function(e) {
if( e.button == 0 ) { // Clicked with left mouse button
alert('You clicked with left mouse button');
}
});
});
</script>

<a id="click-me">Click me</a>

ubuntudog.com © 2017 | About | Sitemap | Contact