Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick a href question 2

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
is there any way of collating all <a href> tags in the body of an html page and storing them in some kind of list.

thanks
cajchris
 
what using HTML or CSS , don't think so, would be interesting to see if anyone else knows a way.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Sure... use the following structure:
Code:
<ul>
  <li><a href="[URL unfurl="true"]http://www.xxx.yyy">Some[/URL] link</a></li>
  <li><a href="[URL unfurl="true"]http://www.xxx.yyy">Some[/URL] link 2</a></li>
...
  <li><a href="[URL unfurl="true"]http://www.xxx.yyy">Final[/URL] link</a></li>
</ul>
By placing an ID on the <ul> you can use CSS to position it anywhere you like on the page.

You can build this up manually and save it on the page if you wanted to... a fine solution for a static web site.

You could do this server-side and generate the above code (which is probably the preferable way to do it).

If you want to do this automagically once the page has loaded, then you would have to resort to using javascript.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
are we getting confused here.... Is this a page your writing, or a page your trying to parse some how?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
sweet nice job, when did the getby TAGNAME get released.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Been around for quite some time... what'd be nice is a native document.getElementsByClassName(). Of course it's not hard to code one, but it'd be nice to have it available in the core.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
if you got by class name, wouldn't that create an array of multiple elements that are all using the same class, or do you mean a way of grabbing the actual class element itself.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
An array of all elements using the same class. The idea would be that you could use it like this:
Code:
var myCollection = document.getElementsByClassName('printme');
for (loop=0;loop<myCollection.length;loop++)
  myCollection[loop].style.display='block';
You currently have to parse the whole DOM and check for the classname of each.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
that looks much nicer, and easier to handle

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top