Welcome to WebmasterWorld Guest from 54.196.107.247

Forum Moderators: open

Message Too Old, No Replies

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

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

New User

10+ Year Member

joined:Dec 20, 2002
posts:15
votes: 0


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

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

Senior Member

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

joined:Mar 20, 2002
posts:3732
votes: 0


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>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members