{"id":787,"date":"2012-06-05T19:02:13","date_gmt":"2012-06-05T19:02:13","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=787"},"modified":"2012-06-05T19:02:13","modified_gmt":"2012-06-05T19:02:13","slug":"jquery-detect-mouse-jquery-detect-mouse-click","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/jquery-detect-mouse-jquery-detect-mouse-click\/","title":{"rendered":"jQuery Detect Mouse (Left Click Right Click Middle Button Click)"},"content":{"rendered":"<p>Did you ever use\u00a0<strong>jQuery to Detect Mouse Click<\/strong>\u00a0on a div or any other element using jQuery? In this article, I am going to discuss a simple and easy way to <strong>detect mouse click\u00a0<\/strong>i.e. you will be able to<strong> detect left click, detect right click &amp; detect mouse middle button click using jQuery<\/strong>.<\/p>\n<p><!--more--><\/p>\n<h2>Examples to Detect Mouse Click ( Left Click, Right Click, Middle Button Click) Using jQuery<\/h2>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=787\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<p>Let&#8217;s assume that you have Div with ID &#8220;my_div&#8221; and you want to <em><strong>detect the mouse click on this div<\/strong><\/em>. In this case, it&#8217;s possible to do the following:<\/p>\n<ol>\n<li>Detect Left Click using jQuery<\/li>\n<li>Detect Middle Button Click using jQuery<\/li>\n<li>Detect Right Click using jQuery<\/li>\n<\/ol>\n<h3>Example: HTML + jQuery Code for mouse click detection<\/h3>\n<pre class=\"lang:xhtml decode:true\" title=\"Example\">\/\/HTML Code\n&lt;div id=\"my_div\" title=\"This is title\"&gt;This is a test div&lt;\/div&gt;\n\n\/\/jQuery Code\n$('#my_div').mousedown(function(event) {\nswitch (event.which) {\ncase 1:\nalert('Left mouse button has been pressed.');\nbreak;\ncase 2:\nalert('Middle mouse button has been pressed.');\nbreak;\ncase 3:\nalert('Right mouse button has been pressed.');\nbreak;\ndefault:\nalert('Invalid request.');\n}\n});<\/pre>\n<div class=\"make_demo\">\r\n\r\n\t<form action=\"https:\/\/theextremewebdesigns.com\/blog\/wp-content\/themes\/ewd_blog_2017\/try_demo.php?post_id=787\" method=\"post\" name=\"form1\" target=\"_blank\" id=\"form1\">\r\n\r\n\r\n\t<input type=\"hidden\" name=\"shortcode_content\" id=\"shortcode_content\" value=\"\" \/>\r\n\r\n        <div class=\"try_demo_btn_container\">\r\n\r\n\r\n            <button type=\"submit\" name=\"sbt_make_demo\" id=\"sbt_make_demo\" class=\"btn-primary btn-try-demo\">\r\n                Try Demo\r\n            <\/button>\r\n\r\n\r\n        <\/div><!-- .try_demo_btn_container -->\r\n\r\n    <\/form>\r\n    <\/div>\r\n    \n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <em><strong>detect mouse click using jQuery<\/strong><\/em>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you ever use\u00a0jQuery to Detect Mouse Click\u00a0on a div or any other element using jQuery? In this article, I am going to discuss a simple and easy way to detect mouse click\u00a0i.e. you will be able to detect left click, detect right click &amp; detect mouse middle button click using jQuery.<\/p>\n","protected":false},"author":1,"featured_media":395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20,13],"tags":[42,41],"class_list":["post-787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery-tips-and-tricks","category-tips-and-tricks","tag-jquery-demos-2","tag-jquery-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-cH","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=787"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}