Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Get all href values in <ul> group and compare with current url

Reply
Thread Tools

Get all href values in <ul> group and compare with current url

 
 
michael
Guest
Posts: n/a
 
      05-05-2005
> 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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      05-05-2005
michael wrote:
>> 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
>


Don't know why you get the error, I tested in IE and Firefox. Have
you created files for each link? And included the modified URL/href
line?

--
Rob
 
Reply With Quote
 
 
 
 
Michael Winter
Guest
Posts: n/a
 
      05-05-2005
On 05/05/2005 03:50, RobG wrote:

[snip]

> Sorry, forgot IE doesn't do document.URI, try this: [...]


Not URI, no, but URL, yes. Unless Microsoft are lying in their
documentation, it's been included in all versions, on all supported
platforms, since 4.0.

Have you found a version where it fails to work, or are you just
assuming it doesn't?

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      05-05-2005
On 05/05/2005 06:42, michael wrote:

[snip]

> I get a javascript error:


[snip]

> if ( \bhead\b.test(x.className) ){


Where have the forward slashes gone?

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.


Yes. The parsing error within the function causes the parser to halt the
creation of the function object. When the browser tries to call doClass
in response to the load event, it fails as the object doesn't exist.

> --
> The first duty of a revolutionary is to get away with it.
> -- Abbie Hoffman


FYI: Your signature separator seems to be broken. It should be
dash-dash-space.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
michael
Guest
Posts: n/a
 
      05-05-2005
> Where have the forward slashes gone?

Thanks for mentioning it, I suspect something's wrong with my Linux
font-config set-up or X-windows, or just the newsreader itself.
I just viewed source of the posting and indeed found the missing forward
slashes- I shall try again with "/" and I'm sure it will work much better!

Michael

--
"Don't worry about people stealing your ideas. If your ideas are any
good, you'll have to ram them down people's throats."
-- Howard Aiken
 
Reply With Quote
 
michael
Guest
Posts: n/a
 
      05-09-2005
> <li><a href="z4.html">Pretty&nbsp;fish</a></li>
> <li><a href="z5.html">Don&#39t&nbsp;eat</a></li>
> </ul>
> </li>
> </ul>
> </div>
> </body>
> </html>
>
>



This works great!

But does anyone know how to get it working as a horizontally aligned drop
menu, only showing 'sub' list items when hovering over the first <li> of
each <ul class="head low">, so if for example hovering over Flora & Fauna
or any of its sub-links, show:

[Flora & funa] [Aquatic creatures[
[Pretty flowers]
[Deadly vines]

And retaining the background scheme for all items, but with a variable, so
the current page is not actually a link?

--
Blore's Razor:
Given a choice between two theories, take the one which is
funnier.

 
Reply With Quote
 
michael
Guest
Posts: n/a
 
      05-10-2005
I pieced together a hover-drop-menu derived from
htmldog.com/articles/suckerfish/dropdowns with the colour-by-URL modifier
script solution as posted by Rob earlier.

The new styles basically removes the sub-listed items from view, leaving
only the first LI of the <ul class="head low"> visible until mouse hovers
over it, to bring its sub-points back into view.

The background colour works for the LI's on top, which are always visible,
but not for the sub-points for some reason.
Although font styles do take effect across a complete lists, for example: ..

..high {background-color: #99FFCC; font-size:80%;}

... makes a smaller font on all items in the group containing current URL.

Anyone has any idea why the background colours doesn't take effect behind
the sub-points?

See complete page below:

<html><head><title></title>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<style type="text/css">

#menu, #menu ul {
padding: 0;
margin: 0;
list-style:none;
}

#menu a {
display: block:
width: 10em:
}

#menu ul {
float: left;
width: 10em;
}

#menu li ul {
position: absolute;
width: 10em;
left: -999em;
}

#menu li:hover ul {
left: auto;
}

#menu li:hover ul{
left: auto;
}


#menu li.sfhover ul{ /* ie specific, but alignment not yet working */
left: auto;
margin-top:1em;margin-left:-1em;
}


..high {background-color: #99FFCC; font-size:80%;}
..low {background-color: #33CC00;}

</style>

<script type="text/javascript">

function doClass(){
var As, ff, x;
var a = RegExp('.*/'); // Needed many times, compile for speed
var f = document.URL.replace(a,''); // filename of current page
var d = document.getElementById('menu');
var uls = d.getElementsByTagName('ul');

for (var i=0, j=uls.length; i<j; i++){
x = uls[i];

// If the UL className string includes word 'head'
if ( /\bhead\b/.test(x.className) ){

// Get its A elements
As = x.getElementsByTagName('a');

// Search for matching file names
for (var k=0, m=As.length; k<m; k++) {
ff = As[k].href.replace(a,'');

// If match, modify the className string of the parent UL
if ( ff == f ){
x.className = x.className.replace(/\blow\b/,'high');

// No need to continue once we've found one
return;
}
}
}
}
}
</script>


<script language="javascript">

/* the suckerfish script to fix IE compatibility in bringing the sub-menu
items back in view, although not as intended directly under its headings */

sfHover = function() {
var sfEls = document.getElementById("menu").getElementsByTagNa me("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

</script>


</head>


<body onload="doClass();">

<div id="menu">

<ul class="head low">


<li><a href="z0.html">Flora&nbsp;&amp;&nbsp;puna</a>

<ul class="sub">
<li><a href="z1.html">Pretty&nbsp;flowers</a></li>
<li><a href="z2.html">Deadly&nbsp;vines</a></li>
</ul>


</li>

</ul>
<ul class="head low">


<li><a href="z3.html">Aquatic&nbsp;creatures</a>

<ul class="sub">
<li><a href="z4.html">Pretty&nbsp;fish</a></li>
<li><a href="z5.html">Don&#39t&nbsp;eat</a></li>
</ul>

</li>


</ul>
</div>

</body>
</html>

--
One way to make your old car run better is to look up the price of a
new model.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASE HREF and A HREF="#" onclick="..." Vincent van Beveren Javascript 2 07-06-2006 08:33 AM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
onClick method question (this.href and document.location.href) yogesh.bhardwaj@gmail.com Javascript 2 02-03-2005 02:38 PM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM
Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src Soren Vejrum Javascript 4 07-05-2003 01:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57