If you use jQuery, the easiest way is to get the id of this specific link, for example
<a href="http://www.stackoverflow.com" id="testlink">Click here to go to stack overflow</a> <script type="text/javascript"> $(document).ready(function(){ var linktext=$('#testlink').text(); }); </script>
or if you are not using jquery
<script type="text/javascript"> var linktext=document.getElementById('testlink').text; </script>
If you do not use jquery, do not forget to put javascript after the html anchor is declared, otherwise the code will not work, since the anchor will not exist if the script is running, if javascript matches before the html anchor.
source share