title: Javascript to get index of all anchor links
body: <p>Jquery version 1.4 supports <a href="https://api.jquery.com/index/" rel="nofollow">.index()</a> function, but our older environment only supports 1.3, so I can't use .index() until we upgrade later this year.</p>
  
  <p>So, this is my approach at using a mix of traditional javascript with .length and jquery click function to get the index of each anchor when clicked, but my Demo 1 approach returns the total anchors on a page when clicked. </p>
  
  <p>I need your help to make this function extremely simple using onclick (perhaps without an argument) as I need to use it in multiple functions.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$("a").click(function() {
        var links = document.links;
        for (var i = 0; i &lt; links.length; i++) {
          var link = document.getElementsByTagName("a").length
          alert(link)
          return false;
        }
      });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;a href="http://www.google.com"&gt;Google Link&lt;/a&gt;
  &lt;a href="http://www.google.com"&gt;Google Link&lt;/a&gt;
  
  &lt;ul&gt;
    &lt;li&gt;&lt;a href="http://www.google.com"&gt;Google Link&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.google.com"&gt;Google Link&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>For example, if I had at least 1.4 jQuery I would use this approach and the result in this demo is the expected behavior I'm looking for:</p>
  
  <pre><code>$("a").click(function () {
      var count = $(this).index('a');
      alert('link' + count);
      return false;
  });
  </code></pre>
  
  <p>Demo 2: <a href="http://jsfiddle.net/43tmut7t/16/" rel="nofollow">http://jsfiddle.net/43tmut7t/16/</a></p>