Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: open

Message Too Old, No Replies

How do I get the href attribute of a HTML tag from Javascript

     

dbasch

12:40 am on Dec 28, 2002 (gmt 0)

10+ Year Member



Hello,
I need to be able to get the HREF attribute of a link tag from javascript.

Heres the link:


<a href="mockup2.htm" id="corporateSubMenuOneActuator" class="corporatesubmenuoneactuator">Overview</a>

And the javascript that isnt working for me:

if (actuatorType == "linkActuator")
{
window.location = menu.url;
}

menu

How do I get the value of the links HREF?

Thanks,
Derek Basch

korkus2000

6:32 pm on Dec 28, 2002 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Your going to need to use the links array.

document.links[i].href="url";

where i is the number of the link in the array.

document.links[1].href="url"; // = mylink.com from below if those are the only links on the page or the first three.

<a href="yourlink.com">test1</a>
<a href="mylink.com">test1</a>
<a href="theirlink.com">test1</a>

Try something like this

<script>
function locateHref(arraynum){
var arraynum;
var whatHref;
whatHref = document.links[arraynum].href;
alert(whatHref);
}
</script>


<a href="yourlink.com" onclick="locateHref(0)">test1</a>
<a href="mylink.com" onclick="locateHref(1)">test1</a>
<a href="theirlink.com" onclick="locateHref(2)">test1</a>

 

Featured Threads

Hot Threads This Week

Hot Threads This Month