title: How to check whether dynamically attached event listener exists or not?
body: <p>Here is my problem: is it somehow possible to check for the existence of a dynamically attached event listener? Or how can I check the status of the &quot;onclick&quot; (?) property in the DOM? I have searched the internet just like Stack Overflow for a solution, but no luck. Here is my html:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;a id=&quot;link1&quot; onclick=&quot;linkclick(event)&quot;&gt; link 1 &lt;/a&gt;
  &lt;a id=&quot;link2&quot;&gt; link 2 &lt;/a&gt; &lt;!-- without inline onclick handler --&gt;
  </code></pre>
  <p>Then in Javascript I attach a dynamically created event listener to the 2nd link:</p>
  <pre class="lang-js prettyprint-override"><code>document.getElementById('link2').addEventListener('click', linkclick, false);
  </code></pre>
  <p>The code runs well, but all my attempts to detect that attached listener fail:</p>
  <pre class="lang-js prettyprint-override"><code>// test for #link2 - dynamically created eventlistener
  alert(elem.onclick); // null
  alert(elem.hasAttribute('onclick')); // false
  alert(elem.click); // function click(){[native code]} // btw, what's this?
  </code></pre>
  <p><a href="https://jsfiddle.net/qv0k7Lor/" rel="noreferrer">jsFiddle is here</a>.
  If you click &quot;Add onclick for 2&quot; and then &quot;[link 2]&quot;, the event fires well,
  but the &quot;Test link 2&quot; always reports false.
  Can somebody help?</p>