[Javascript] getElementsByTagName not working ???

Roger Roelofs rer at datacompusa.com
Thu Jul 21 07:47:38 CDT 2005


James,

Can you post a url?  I'm not seeing anything wrong with the code you  
posted, but there's nothing like a real web page to flush out bugs.   
By the way, in this case you could more easily do this...

document.getElementById("splink").href = "http://www.google.com";

since the link has an id anyway.

On Jul 21, 2005, at 8:25 AM, James wrote:

> Hi,
>
> this code doesn't work but I can't figure out what is wrong with  
> it, it should be very simple, there are only 3 lines of script....
>
> Thanks for any help.
>
> James
>
> SCRIPT
>
> var all_links = document.getElementsByTagName('a');
> var sitepoint_link = all_links[0];
>
> // using our sitepoint_link variable from above
> sitepoint_link.href = "http://www.google.com/";
>
>
> /////////////////////////
> HTML
>
> <div id="codesection">
> <p id="codepara">
> </p>
> <ul>
> <li><a href="http://www.sitepoint.com/" id="splink">SitePoint</a></li>
> <li><a href="http://www.yahoo.com/" id="yalink">Yahoo!</a></li>
> </ul>
> </div>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>




More information about the Javascript mailing list