Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to understand useCapture parameter in addEventListener
    primarykey
    data
    text
    <p>I have read article at <a href="https://developer.mozilla.org/en/DOM/element.addEventListener" rel="noreferrer">https://developer.mozilla.org/en/DOM/element.addEventListener</a> but unable to understand <code>useCapture</code> attribute. Definition there is:</p> <blockquote> <p>If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTargets beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture. </p> </blockquote> <p>In this code parent event triggers before child,so I am not able to understand its behavior.Document object has usecapture true and child div has usecapture set false and document usecapture is followed.So why document property is preferred over child.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function load() { document.addEventListener("click", function() { alert("parent event"); }, true); document.getElementById("div1").addEventListener("click", function() { alert("child event"); }, false); }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body onload="load()"&gt; &lt;div id="div1"&gt;click me&lt;/div&gt; &lt;/body&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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