[Javascript] getElementsByTagName not working ???

James james at southspace.org
Thu Jul 21 07:50:40 CDT 2005


Thanks!! I never would have guessed!

James

At 13:47 21/07/2005, you wrote:
>The problem probably is "when" you are running the script, if you set it 
>to be something like
>
>< script >
>  (...)
>< /script>
>< html>
>  (...)
>< /html>
>
>  The script will run "in execution/loading time" (I don't know a better 
> expression)  and when it get to the "getElementsByTagName" line there's 
> not any "A" tag loaded in dom/html yet, so it(the script) won't see them. 
> Just by putting the script after the html, on triggering it on the 
> "onload" event should do.
>
>--
>Flavio Gomes
>flavio at economisa.com.br
>
>
>
>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