title: Calling a javascript function by using onClick in a hyperlink
body: <p>I have been looking online, but I have failed to find a direct answer to my question:</p>
  
  <p><strong>Can you use onClick for a tags?</strong></p>
  
  <p>In other words can you do this (note echoed through php)?</p>
  
  <pre><code>echo "&lt;a href=\"#\" id =\"loginbutton\" onClick=\"counter()\"&gt;&lt;/a&gt;\n";
  </code></pre>
  
  <p>I tried to run this, but when I click on the link, my counter function is not being called.</p>
  
  <p>The rest of my code snippet:</p>
  
  <pre><code>echo "&lt;script type=\"text/javascript\" src=\"src\jquery\jquery.js\"&gt;\n";
  echo "function counter(){\n";
  echo "alert(\"HELLO WORLD!\");\n";
  echo "}\n";
  echo "&lt;/script&gt;\n";
  
  echo "&lt;a href=\"#\" id =\"loginbutton\" onClick=\"counter()\"&gt;&lt;/a&gt;\n";
  </code></pre>