title: Getting calling element (anchor) dynamically with JavaScript
body: <p>How would I go about getting the text of an anchor tag using JavaScript. I know how to do this by attaching an ID to the tag but I was wondering if there's anyway to do it using the "this" keyword.</p>
  
  <p>Example HTML Snippet:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;&lt;a href="javascript:alertText(this);"&gt;Link One&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="javascript:alertText(this);"&gt;Link Two&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>JavaScript Function:</p>
  
  <pre><code>function alertText(callingElement) {
      alert(callingElement.text);
  }
  </code></pre>
  
  <p>This is not working (alert is printing out "undefined") because the "this" keyword seems to be pointing at the Window object instead of the anchor that called the function.</p>
  
  <p>Using JQuery is an option if it is necessary.</p>