title: How to prevent default action for an Anchor tag using Javascript?
body: <p>I'm trying to prevent default action on an anchor ("a") tag. In my scenario few lines of html are rendered on the fly using ajax (after a form is submitted) and I want to add an event listener that </p>
  
  <ol>
  <li><p>performs an action when a newly created link is clicked</p></li>
  <li><p>prevent the browser from opening that link.</p></li>
  </ol>
  
  <p>Here's what I'm writing:</p>
  
  <pre><code>a = document.getElementById("new_link");
  a.addEventListener("click",function(){alert("preform action");
                                        return false;},false);
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>a.addEventListener("click",function(e){e.preventDefault(); alert("preform action");});
  </code></pre>
  
  <p>When I click on the link "a" it shows the alert message but still opens the "href" link where as I want it to show the message and then stop.</p>
  
  <p>Both methods show alerts if attached to an pre-existing link but do not work when attached to newly inserted links (via ajax).. which is what I need to do.</p>
  
  <p>Any help/suggestions.</p>
  
  <p>Thanks.</p>