473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

IE Error: 'parentNode' is null or not an object

Without showing any code, I thought maybe somebody already knows what
the error message in the title generally means?

But in short, a menu is supposed to display by setting its inline style
attribute to: display="none" vs 'display="block" upon an onclick of an
"<a>" element. That link ("<a>") element is accessed via DOM by using
something like "this.parentNode.childNodes[2].style.display="none", or
"block" to display a menu below it.
The code works in Firefox, and the menu shows up & hides, but IE6 gives
this error, despite that it's supposed to support the 'parentNode'
property. What could it be?

-Help's appreciated.

Nov 19 '06 #1
7 37870
webdeveloper wrote:
Without showing any code, I thought maybe somebody already knows what
the error message in the title generally means?

But in short, a menu is supposed to display by setting its inline style
attribute to: display="none" vs 'display="block" upon an onclick of an
"<a>" element. That link ("<a>") element is accessed via DOM by using
something like "this.parentNode.childNodes[2].style.display="none", or
"block" to display a menu below it.
The code works in Firefox, and the menu shows up & hides, but IE6 gives
this error, despite that it's supposed to support the 'parentNode'
property. What could it be?
If the onclick event was attached using attachEvent, then likely in IE
the function's this value is the global/window object, and not the
element. In Gecko et al, presuming you've used addEventListener, it
refers to the element.

--
Rob

Nov 19 '06 #2
ASM
webdeveloper a écrit :
The code works in Firefox, and the menu shows up & hides, but IE6 gives
this error, despite that it's supposed to support the 'parentNode'
property. What could it be?
I don't know about IE (Win)
but all examples bellow work fine in my browsers.

Your method :

<li><a href="11.htm" onclick="
var submenu = this.parentNode.childNodes[2].style;
submenu.display = submenu.display==''? 'none' : '';
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

My method :

<li><a href="11.htm" onclick="
var submenu = this.parentNode.getElementsByTagName('ul')[0].style;
submenu.display = submenu.display==''? 'none' : '';
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

Much more complicated :

<li><a href="11.htm" onclick="
var parentMenu = this.parentNode;
while(parentMenu.tagName.toLowerCase()!=('li'))
parentMenu += parentNode;
var submenu = parentMenu.childNodes;
for(var i=0; i<submenu.length; i++)
if(submenu[i].tagName &&
submenu[i].tagName.toLowerCase()=='ul') {
submenu = submenu[i].style
submenu.display = submenu.display==''? 'none' : '';
}
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Nov 19 '06 #3
Well, thanks; that gives a clue that the code might be correct, at
least. Although some 80% won't be able to use it until I can figure why
IE gives the darn error instead of obeying the DOM. I might repost
(with the code) if I can't figure out a solution.

Thanks


I don't know about IE (Win)
but all examples bellow work fine in my browsers.

Your method :

<li><a href="11.htm" onclick="
var submenu = this.parentNode.childNodes[2].style;
submenu.display = submenu.display==''? 'none' : '';
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

My method :

<li><a href="11.htm" onclick="
var submenu = this.parentNode.getElementsByTagName('ul')[0].style;
submenu.display = submenu.display==''? 'none' : '';
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

Much more complicated :

<li><a href="11.htm" onclick="
var parentMenu = this.parentNode;
while(parentMenu.tagName.toLowerCase()!=('li'))
parentMenu += parentNode;
var submenu = parentMenu.childNodes;
for(var i=0; i<submenu.length; i++)
if(submenu[i].tagName &&
submenu[i].tagName.toLowerCase()=='ul') {
submenu = submenu[i].style
submenu.display = submenu.display==''? 'none' : '';
}
return false;
">page 11</a>
<ul>
<li><a href="11a.htm">page 11-a</a></li>
<li><a href="11b.htm">page 11-b</a></li>
</ul>
</li>

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Nov 20 '06 #4

webdeveloper wrote:
Well, thanks; that gives a clue that the code might be correct, at
least. Although some 80% won't be able to use it until I can figure why
IE gives the darn error instead of obeying the DOM. I might repost
(with the code) if I can't figure out a solution.
It's because in IE this attribute is named "parent" instead of
"parentNode". You have to use code like:

var parent = node.parentNode || node.parent;

Nov 20 '06 #5

webdeveloper wrote:
Well, thanks; that gives a clue that the code might be correct, at
least. Although some 80% won't be able to use it until I can figure why
IE gives the darn error instead of obeying the DOM. I might repost
(with the code) if I can't figure out a solution.
It's because in IE this attribute is named "parent" instead of
"parentNode". You have to use code like:

var parent = node.parentNode || node.parent;

Nov 20 '06 #6
It's because in IE this attribute is named "parent" instead of
"parentNode". You have to use code like:

var parent = node.parentNode || node.parent;
I meant, it's called "parentElement" instead of "parentNode". My
mistake. However, it appears IE also redundantly supports parentNode,
so unless there's some advantage I'm not aware of there's no reason to
use parentElement.

I'm going to bed now.

Nov 20 '06 #7
It seems that the problem was when refering to the onclick element
itself as document.links.name made it unworkable in IE. When changed
into document.getElementById("id"); it started to work, although with
another issue that I'll describe later.

enjoy the dreams:)

David Golightly wrote:
It's because in IE this attribute is named "parent" instead of
"parentNode". You have to use code like:

var parent = node.parentNode || node.parent;

I meant, it's called "parentElement" instead of "parentNode". My
mistake. However, it appears IE also redundantly supports parentNode,
so unless there's some advantage I'm not aware of there's no reason to
use parentElement.

I'm going to bed now.
Nov 21 '06 #8

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

Similar topics

1
by: reinhard | last post by:
Our project was developed with Python 2.0 and includes some Tk 8.3 extension widgets as well as python extensions using the CXX interface. After moving to Python 2.3 and TclTk 8.4 our program...
4
by: Brent P | last post by:
I am moving a site to windows 2003 and after using REGASM to register this object on the new server I get this error. error '80131418' I can not find it referenced anywhere? Thanks Brent
8
by: Robert | last post by:
Hello all, Why reference cannot be able to represent a NULL object? Best regards, Robert
2
by: Pathogenix | last post by:
Greetings, I'm trying to fix a web service client which has been implemented in a dailywtf worthy manner. I've decided to rip all the old code out and start again from the proxy generated by...
15
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
0
by: Alun Jones | last post by:
I'm getting the above error in a dialog box from Visual Studio 2005 when trying to sign an assembly using a PFX file, and would like to know how to resolve the problem. Background: The PFX...
3
by: toton | last post by:
Hi, In some cases when my function returns, I need to return a object of null state. This is when I return object by value. (Just like for by pointer, I can return a null pointer ). It has to be...
2
by: Glenn | last post by:
Rather than... if ( myInstance != null ) { myInstance.Dispose(); } maybe something like this... myInstance?Dispose();
1
by: JWest46088 | last post by:
I'm getting this error when I try to preview my code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at therun4life_fla::MainTimeline/frame1() I don't...
3
karthickkuchanur
by: karthickkuchanur | last post by:
Dear Experts, Please let me know what is the difference between difference between object !=null and null !=object,I already google it but i can't able to find the right answer
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.