PDA

View Full Version : function using "a" or "href"



xtiano77
11-05-2008, 02:43 PM
I wonder if anyone can help me with this. I am trying to write up a function that cycles through the <a href=”…. >whatever link</a> when the user clicks the pseudo link <a href=”javascript:functionname()”>. I know that pretty much all HTML elements on a page can be referred to in array format (forms[], images[], etc.), but I am not sure how or if it is even possible to do that with <a href…>. Any help will be greatly appreciated. Thanks in advance.

boogyman
11-05-2008, 03:30 PM
If you would like this for only one page, put the following inside the <head> tag.



<script type="text/javascript">
function functionname() {
if(document.getElementById) {
var anchorTags = document.getElementByTagName("a");
for(var lcount=0; lcount<anchorTags.length; lcount++)
{
/* do something with each individual anchor tag */
/* anchorTags[lcount] represents the current anchor tag within the loop */
}
}
}
</script>


if you would like this for more then one page, create an external javascript (js) file and link to the script on each page using the following code



<script type="text/javascript" href="path/to/script">
</script>



to access the script itself use the following code located where ever you wished to use the script



<a href="javascript:functionname()">Get all links on this page</a>

xtiano77
11-05-2008, 04:43 PM
Thanks. I appreciate you help.