dumdumsareyum Posted April 5, 2008 Share Posted April 5, 2008 Hi....I would like to be able to create some navigation links using javascript (can't use php cause the files won't necessary be on a server with php, just need to be openable in a browser). I was thinking maybe there is an array to get all the id's listed in the document? Or if there is an array for all the <h1> and <h2> elements that would be even better because I would like to include subtopics in my navigation tree. My Javascript book lists getElementsById and getElementsByName and getElementsByTagName, but it doesn't explain any of them, it's a really crummy book. I didn't know if any of those would work for what I want to do because all I need is a list of what the IDs are, and then i guess i could do a loop on get element by id and display the text of the heading associated with that id..... Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
dumdumsareyum Posted April 6, 2008 Author Share Posted April 6, 2008 here's the function I tried to do this, I thought it might help illustrate what I want to do: function writeNavigation() { var headings = document.getElementsByTagName("h1"); for( var i=0; i< headings.length; i++) { var theID = headings[i].getAttribute("id"); document.write("<a href='index.html#".theID.'>headings[i]</a><br />"); } } Is this headed in the right direction? Quote Link to comment Share on other sites More sharing options...
dumdumsareyum Posted April 6, 2008 Author Share Posted April 6, 2008 nevermind, i figured it out, this is what i was going for: function writeNavigation() { document.write("I'm in the function <br />"); var headings = document.getElementsByTagName('h1'); for(i = 0; i < headings.length; i++) { var theID = headings[i].getAttribute("id"); document.write('<a href="index.html#'+theID+'">'+headings[i].innerHTML+'</a><br />'); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.