i am having a hyperlink control and a button control like this:
Collapse | Copy Code
How can i get the text of the hyperlink using javascript:
i am having a hyperlink control and a button control like this:
Collapse | Copy Code
How can i get the text of the hyperlink using javascript:
you can get like this.
var test=document.getElementById(your link id).text;
//test will return the text of your hyperlink
getelementbyid() (getElementById()).If you are using JQuery The easiest method is to get via id of that particular link such as
<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 don't use jquery
<script type="text/javascript">
var linktext=document.getElementById('testlink').text;
</script>
If you are not using jquery remember to put javascript after the html declaration of anchor otherwise code won't work as anchor would not exist when script is running if javascript comes before anchor html.