![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Jerome Bei wrote: Try this: script uls = document.getElementsByTagName("UL"); for (var u=0; u<uls.length; u++) { alert("entering list ["+u+"]"); lis=uls[u].getElementsByTagName("LI"); for (var i=0; i<lis.length; i++) { if (lis[i].childNodes[0] && lis[i].childNodes[0].href) { |
|
alert("found link ["+lis[i].childNodes[0].href+"]"); } } } /script (Testes on IE 6.0 only) --Jerome Works nicely, fetches the links if there are, and it works on Mozilla too. |
#3
| |||
| |||
|
|
michael wrote: [...] // Given an element ref, descend element tree until an <a> is found // Return a reference to the element or null if not found function hasAchild(x){ isA = false; // global if (x.nodeName == 'A') { isA = x; return isA; // Stop descent on first A element } for (var i=0; i<x.childNodes.length; i++) { // Descend if not found an A yet if (!isA) hasAchild(x.childNodes[i]); } return isA; } |
#4
| |||
| |||
|
|
If anything is inserted between the <li> and <a> tags, even a space, this will fail as the <a> element will no longer be the first child of the <li>. Probably better to use a recursive function to go down the tree from the <li> to see if it has an <a> element as a descendant. |
#5
| |||
| |||
|
|
On 04/05/2005 08:35, RobG wrote: [snip] If anything is inserted between the <li> and <a> tags, even a space, this will fail as the <a> element will no longer be the first child of the <li>. Probably better to use a recursive function to go down the tree from the <li> to see if it has an <a> element as a descendant. Probably better to use getElementsByTagName to find any A elements within a list, directly. An A element would only be valid within a list item, so it seems rather pointless to spend time walking through the tree. |
#6
| |||
| |||
|
|
michael wrote: [...] Any ideas, and especially short code would be greatly appreciated! [...] |
|
var f = document.URL.replace(a,''); // filename of current page |
#7
| |||
| |||
|
|
interested in descendant ULs, you may be) as an example, but my idea of what you are trying to do is probably very different to what you are actually doing. This looks convertable to exactly what I need, perfect! And code can't get much shorter. Only, I get a javascript error: -- Error: illegal character Source File: file:///tmp/z2.html Line: 24, Column: 10 Source Code: if ( \bhead\b.test(x.className) ){ Error: doClass is not defined -- I don't know how to fix that, I guess second error is due to the first. Many thanks, Michael -- The first duty of a revolutionary is to get away with it. -- Abbie Hoffman |
#8
| |||
| |||
|
|
Sorry, forgot IE doesn't do document.URI, try this: [...] |
#9
| ||||
| ||||
|
|
I get a javascript error: |
|
if ( \bhead\b.test(x.className) ){ |
|
Error: doClass is not defined -- I don't know how to fix that, I guess second error is due to the first. |
|
-- The first duty of a revolutionary is to get away with it. -- Abbie Hoffman |
![]() |
| Thread Tools | |
| Display Modes | |
| |