473,507 Members | 4,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Firefox doesn't like collapsible menu JavaScript

The JavaScript below works fine for expandable/collapsible menus in IE,
but Firefox 1.5 complains: "Error: loc.parentNode.nextSibling has no
properties" and highlights the line
foc=loc.parentNode.nextSibling.style?.

Is there a fix to make Firefox happy?

thanks,
Mike

<script type="text/javascript"><!--
function dsp(loc){
if(document.getElementById){
var foc=loc.firstChild;
foc=loc.firstChild.innerHTML?
loc.firstChild:
loc.firstChild.nextSibling;
foc.innerHTML=foc.innerHTML=='+'?'-':'+';
foc=loc.parentNode.nextSibling.style?
loc.parentNode.nextSibling:
loc.parentNode.nextSibling.nextSibling;
foc.style.display=foc.style.display=='block'?'none ':'block';}}

if(!document.getElementById)
document.write('<style type="text/css"><!--\n'+
'.dspcont{display:block;}\n'+
'//--></style>');
//--></script>

body HTML looks like this:

<h3><a href="javascript:void(0)" class="dsphead"
onclick="dsp(this)">
<span class="dspchar">+</span>Search</a></h3>
<div class="dspcont">
<ul>
<li><A HREF="http://www.google.com/">Google</A>
<li><A HREF="http://www.yahoo.com/">Yahoo</A>
<li><A HREF="http://www.teoma.com/index.asp">Teoma</A>
</div>
</h3>

Jan 6 '06 #1
1 2306
mi**@csquared.com wrote:
The JavaScript below works fine for expandable/collapsible menus in IE,
but Firefox 1.5 complains: "Error: loc.parentNode.nextSibling has no
properties" and highlights the line
foc=loc.parentNode.nextSibling.style?.

Is there a fix to make Firefox happy?
Yes.


thanks,
Mike

<script type="text/javascript"><!--
function dsp(loc){
if(document.getElementById){
var foc=loc.firstChild;
foc=loc.firstChild.innerHTML?
loc.firstChild:
loc.firstChild.nextSibling;
I suspect that this is a device to get the SPAN element if there is a
text node placed directly after the div that loc refers to. A better
method might be to progress through the child nodes until the SPAN is
encountered (there may be 0, 1 or more text nodes there).

foc.innerHTML=foc.innerHTML=='+'?'-':'+';
foc=loc.parentNode.nextSibling.style?


Here foc refers to the SPAN. It's parent is the div, whose
nextSibling is the empty text node placed after the closing div tag in
Firefox but not by IE - it's the same situation that you are trying to
avoid above (the empty text nodes are there because of the new lines
in the markup).

You might be better to write a function that returns the next sibling
of a certain tag name, then use it for both situations to ensure you
get the right node. Something like:
function getSibOfTag(el, tag)
{
var k = el.childNodes;
var x;
for (var i=0, len=k.length; i<k; ++i){
x = el.childNodes[i];
if ( x.tagName && tag == x.tagName.toLowerCase()){
return x;
}
}
return null;
}
then call it with:

var foc = getSibOfTag(loc, 'span');
and

foc = getSibOfTag(loc.parentNode, 'h3');
Untested, but hopefully you get the idea.
[...]
--
Rob
Jan 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1602
by: Jeremy Epstein | last post by:
Hi guys, I've got a page that shows a number of packages available for sale. Each package has a little description, and then a (sometimes long) list of features for each package. I thought it...
5
3495
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything...
4
2311
by: lmarceglia | last post by:
Hi, I have this website that doesn't work in Firefox 1.5: www.pianetaluca.com The HTML source is: <TITLE>PianetaLuca</TITLE> </HEAD>
2
6171
by: pantagruel | last post by:
Hi, I'm wondering if CSS support in IE is such that one could make an expandable collapsible vertical menu - such as in a TOC - without using Javascript that will work in at least IE 6. IE 5...
5
5833
by: Jonathan | last post by:
Hello All, I am in the process of creating a 2/3 level collapsible/exspanible menu (called "nav") where users can click on a category and have the submenus appear beneath it and so on (allow...
12
2556
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
3
3231
by: Arielle | last post by:
Problem: Using an XHTML doctype for all our pages, this is not optional. The layout the client wants to use requires the site to be "full screen" with a header, footer, horizontal menu, and main...
7
2659
by: David T. Ashley | last post by:
I'm trying to implement these ... I know there is a lot of example code on the web, but I'm trying to roll my own ... What JavaScript functionality is typically used to display parts of the...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.