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.
Example HTML Snippet:
<ul>
<li><a href="javascript:alertText(this);">Link One</a></li>
<li><a href="javascript:alertText(this);">Link Two</a></li>
</ul>
JavaScript Function:
function alertText(callingElement) {
alert(callingElement.text);
}
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.
Using JQuery is an option if it is necessary.