Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] getElementsByTagName not working ???


  • From: flavio at economisa.com.br (Flavio Gomes)
  • Subject: [Javascript] getElementsByTagName not working ???
  • Date: Thu Jul 21 07:46:57 2005

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@xxxxxxxxxxxxxxxx



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>