M
michael
Is it possible to get all href URLs contained in a unordered list and place
them in an array?
Or in fact two different arrays, differently named one for each <ul> group?
<ul>
<li><a href="lemurs.html">Lemurs</a></li>
<li><a href="chameleons.html">Chameleons</a></li>
</ul>
<ul>
<li><a href="sharks.html">Sharks</a></li>
<li><a href="crocs.html">Crocodiles</a></li>
</ul>
I want to fetch an array of the links within a <ul> group, and
document.write the above, but with class variable in which I can
set a different value, depending on if the current url filename matches
exactly any one of the links within the <ul> group the <li> belongs to.
More specifically, I would like to ...
document.write('<li class'+myvariable+'>')
|
... class 'green' or 'blue' -------'
depending on whether filename in any href contained
in an <li> of the <ul> group it is in.
If an exact match is found, write out green, if not blue.
The file name portion of the current URL I simply get through:
var f = window.location.href;
file = i.substring (f.lastIndexOf('/') +1);
It is for drop-down nav-system whereby all list items would of a ul group
would appear either one of two colours as specified in css properties. All
links are internal links on the same domain so one would always match.
I could naturally do it all by having a pre-typed list of all filenames and
run each <li> through an if statement before writing it out. But as there
will be many <li>'s I would prefer a more typeless method if possible.
Many thanks for any tips!
Michael
them in an array?
Or in fact two different arrays, differently named one for each <ul> group?
<ul>
<li><a href="lemurs.html">Lemurs</a></li>
<li><a href="chameleons.html">Chameleons</a></li>
</ul>
<ul>
<li><a href="sharks.html">Sharks</a></li>
<li><a href="crocs.html">Crocodiles</a></li>
</ul>
I want to fetch an array of the links within a <ul> group, and
document.write the above, but with class variable in which I can
set a different value, depending on if the current url filename matches
exactly any one of the links within the <ul> group the <li> belongs to.
More specifically, I would like to ...
document.write('<li class'+myvariable+'>')
|
... class 'green' or 'blue' -------'
depending on whether filename in any href contained
in an <li> of the <ul> group it is in.
If an exact match is found, write out green, if not blue.
The file name portion of the current URL I simply get through:
var f = window.location.href;
file = i.substring (f.lastIndexOf('/') +1);
It is for drop-down nav-system whereby all list items would of a ul group
would appear either one of two colours as specified in css properties. All
links are internal links on the same domain so one would always match.
I could naturally do it all by having a pre-typed list of all filenames and
run each <li> through an if statement before writing it out. But as there
will be many <li>'s I would prefer a more typeless method if possible.
Many thanks for any tips!
Michael