title: dynamic <a href> event without replacing
body: <p>Hey im having a problem creating a dynamic ahref event. The problem is that i dont want it to perform the default event of just linking. So i have blocked the default and want to replace content inside a div like so, here is the working code:</p>
  
  <pre><code>echo '&lt;a href="/mydirectory/index.php?id=',$id,'"&gt;';
  echo '&lt;script&gt;
  $( "a" ).click(function( event ) {
    event.preventDefault();
   $(".container2").load("/mydirectory/index.php?id=',$id,'");';
  echo '}); &lt;/script&gt;';
  </code></pre>
  
  <p>This works perfectly as i expeted, the problem is that by using this:</p>
  
  <pre><code>$( "a" ).click(function( event ) {
  </code></pre>
  
  <p>It sets all elements of 'a' on the page to link to the last link clicked. However using a unique ID on the href seems to redirect just directly to the html rather than replacing the content and there are no errors when i checked on chrome:</p>
  
  <pre><code>&lt;a href="/mydirectory/index.php?id=',$id,'" id="mylink"&gt;
  $( "#mylink" ).click(function( event ) {
  </code></pre>
  
  <p>So my question is simply, how do i retain the functionality that seems to work for some reason only on the a href and stop it replacing all the a-hrefs elsewhere in the site with the same function?</p>