Getting link text within a div
html, javascript
Solution
var text = document.getElementById('myDiv')
.getElementsByTagName('a')[0].innerHTML;
alert(text); // TEXT
Live DEMO
If you can use jQuery...:
var text = $('#myDiv .myClass a').text();
Problem
I currently have an href that I'd like to pull text from. Unfortunately I don't have access to to code, and the limited code I have to work with is the following: ``` <div id="myDiv"> <h1 class="myClass"> <a href="link">TEXT</a> </h1> </div> ``` I'd prefer using JavaScript to obtain this information. What would be the best way to reference 'TEXT'? I've tried a couple methods using `getElementById` and `getElementsByClassName`, but each have proven unsuccessful. Thanks!