homepage Welcome to WebmasterWorld Guest from 54.81.170.186
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

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




msg:1471226
 12:40 am on Dec 28, 2002 (gmt 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

 

korkus2000




msg:1471227
 6:32 pm on Dec 28, 2002 (gmt 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>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved