Jump to content

getElementsByTagName("a")


Guest N3k
 Share

Recommended Posts

Hello Everyone,This is my first post.I was writting some javascript (which i am also new at) into my blog and I was attempting to use the getElementsByTagName function with the 'a' tag as an argument. Whenever I would put the code into my "header" section of my blog so that it would load the code when the page loads, it would return 0 for the length of the array. But! I created a button on the page itself and assigned it the same task, and the button works fine and comes up with 137 elements or so. What I figure is that the code in the "header" loads before the page loads so there are no elements at the time the code is loaded. Thats my guess anyway. If that makes sense, is there a way to delay the code to load after the page loads, but without assigning it to a manual button or such. I want it to work automatically when the page loads.Thank you very much,Nick

Link to comment
Share on other sites

  • 2 years later...
Guest FirefoxRocks

That or put in it a function (as shown above) and call it in the <body> element using onload like this:

<body onload="getLinks()">

...or whatever you called it as.

Link to comment
Share on other sites

Best yet: place the script at the very bottom of your HTML document, right before the </body> tag. It will execute as soon it has been downloaded (i.e. after the rest of the document has been downloaded already) and is consistent across browsers.

Link to comment
Share on other sites

Anyone checked the first post's date?Oct 10 2005, 08:25 AMFirefoxRocks, have you been using the search function to find posts, then responding to them?

Link to comment
Share on other sites

OMFG. I sure didn't looked at it :) . Then again, I haven't exactly seen this question before, or it hasn't caught my attention at least.

Link to comment
Share on other sites

Well, how many people remember unremarkable forum entries from almost three years ago? :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...