View Full Version : Javascript Menubar Error 'lastChild' is null or not an object

08-18-2011, 01:20 AM
Hey Guys,

I wondered if anyone would be kind enough to look at an issue I am having running a Javascript on IE.

The script works fine in FF and Chrome but chucks up an error in all versions of IE so the Menubar does not display child pages.

Here's the Error:

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Timestamp: Tue, 16 Aug 2011 14:45:53 UTC

Message: 'lastChild' is null or not an object
Line: 31
Char: 3
Code: 0

The full script is here: http://www.makingtrails.com/wp-content/themes/blocks3/js/menu.js

Any help much appreciated as the author of this script is not providing any support.



Old Pedant
08-18-2011, 03:01 AM
Debug time?

For starters, I'd do alert(this.body.lastChild) just before the problem line. See if indeed that gives null or gives an [Object] (I think that's what MSIE would show).

If it shows [Object] then apparently the cleanWhitespace is doing something nasty to this.body.

If it shows null then apparently MSIE doesn't see that this.body has a lastChild. Which begs the question as to just what MSIE thinks this.body refers to. For that matter, maybe doing alert(this.body.firstChild) might reveal something.

If you want more help, though, I think you need to show us the problem in a live page.

09-25-2011, 04:09 AM
Thanks for your reply.

I tried alert(this.body.lastChild) but showed as null

Debugged in IE9 and got a slighty different notification.

Unable to get value of the property 'getElementsByTagName': object is null or undefined

cleanWhitespace(this.body).lastChild.getElementsByTagName('a')[0].className += ' last';

This error is occurring while attempting to load the navigation menu on http://www.makingtrails.com


09-25-2011, 04:30 AM
The menu is working in IE under http://testing.makingtrails.com

Same script though, maybe now it's a conflict.