Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Normally when you have any kind of mouse event, you'll want to have it only operate on one type of mouse click. Therefore, the events passed to your callbacks have a property which allow you to distinguish between types of clicks.</p> <p>This data is passed back through the <strong>button</strong> property of the event data. See <a href="https://developer.mozilla.org/en-US/docs/Web/API/event.button" rel="noreferrer">MDN</a> for finding out what values represent what data.</p> <p>Therefore, you don't disable the right click, you instead only enable your functionality for the left click. Here's a [poor] example:</p> <pre><code>element.onmousedown = function(eventData) { if (eventData.button === 1) { alert("From JS: the (left?) button is down!") } } </code></pre> <p>the equivalent in jQuery is:</p> <pre><code>$("div").mousedown(function(eventData) { if (eventData.which === 1) { alert("From JQuery: which=" + de.which) } }); </code></pre> <p>Note that if you don't use jquery, the values returned will be different across browsers. jQuery <a href="https://api.jquery.com/mousedown/" rel="noreferrer">unifies the values across browsers</a>, using 1 for left, 2 for middle, 3 for right:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code> element.onmousedown = function(eventData) { if (eventData.button === 0) { console.log("From JS: the (left?) button is down!") } } $("#element").ready(function() { $("div").mousedown(function(de) { console.log("From JQuery: which=" + de.which); }); });</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="element" style="width: 100px; height: 100px; background-color: blue" /&gt;</code></pre> </div> </div> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload