Guest N3k Posted October 9, 2005 Share Posted October 9, 2005 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 More sharing options...
Webworldx Posted October 9, 2005 Share Posted October 9, 2005 Try something like: <script type='text/javascript'>function doCode(){ alert(document.getElementsByTagName('A').length);}window.onload=doCode</script> Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 19, 2008 Share Posted July 19, 2008 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 More sharing options...
boen_robot Posted July 19, 2008 Share Posted July 19, 2008 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 More sharing options...
Synook Posted July 19, 2008 Share Posted July 19, 2008 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 More sharing options...
boen_robot Posted July 19, 2008 Share Posted July 19, 2008 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 More sharing options...
Synook Posted July 19, 2008 Share Posted July 19, 2008 Well, how many people remember unremarkable forum entries from almost three years ago? Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 19, 2008 Share Posted July 19, 2008 No, the only forum I use search on is the Ubuntu Forums and mozillaZine. I don't like using search mostly. Link to comment Share on other sites More sharing options...
Synook Posted July 20, 2008 Share Posted July 20, 2008 then how did you find this topic? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now