Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  58] [ 3]  / answers: 1 / hits: 17064  / 11 Years ago, wed, september 18, 2013, 12:00:00
<a href=href>inner</a>


Function below doesn't work because there's no id:



document.getElementById(???).href

More From » javascript

 Answers
2

You can use getElementsByTagName to find the a elements:



var anchor = document.getElementsByTagName(a);


This will store all a elements into an array. If you know exactly which element you want, extract it from the array based on its order in the page and grab the href:



var href = anchor[1].href;


Example jsfiddle (watch for the alert)


[#75622] Tuesday, September 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
vaughns

Total Points: 20
Total Questions: 112
Total Answers: 112

Location: Falkland Islands
Member since Mon, Jul 13, 2020
4 Years ago
;