To find the number of links in the page you would use
document.links.length
You can then use the link array to reference a link.
Test Link 1 is the first link in this page and is referenced as
document.links[0] where 0 is the ordinal number.
Use these buttons to get the url and text of this link
This was done by using document.links[0] and document.links[0].innerHTML
You can change the url and text of this link by using
document.links[0].href='newPage.htm' and document.links[0].innerHTML='New Page'
After pressing one of the following 2 buttons press the appropriate button above and see that the relative link value has changed
Once these value are changed you will have to refresh the page to reload the default values for that link.
You can define a group of links within a page simply by nesting the links inside a div.
You would then find out how many links are in this group by referencing the group like this
document.getElementById('group1').getElementsByTagName('A')
<script type="text/javascript">
<!--
function chk_group1(){
group1_elements=document.getElementById('group1').getElementsByTagName('A')
link_href=""
link_text=""
for(var i=0;i<group1_elements.length;i++){
link_href+=group1_elements[i].href+"\n"
link_text+=group1_elements[i].innerHTML+"\n"
}
alert("There are " + group1_elements.length + " links in group 1\n\n" + link_href + "\n\nThe text for these links is\n" + link_text)
}
// -->
</script>
<div id="group1">
<input type="button" value="Check Group 1" onclick="chk_group1()">
document.links[n].title="HELLO WORLD"
document.links[n].style.color="red"
document.links[n].id="active_link"
document.links[n].style.fontStyle="italic"
<a href="page5.htm">Page 5</a>
<a href="page6.htm">Page 6</a>
<a href="links.htm">Links</a>
<a href="page8.htm">Page 8</a>
Note:
An alternative method to using document.links is getElementsByTagName('A')