Web Analytics Made Easy -
StatCounter Javascript Menubar Error 'lastChild' is null or not an object - CodingForum

Announcement

Collapse
No announcement yet.

Javascript Menubar Error 'lastChild' is null or not an object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript Menubar Error 'lastChild' is null or not an object

    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-conte...ks3/js/menu.js

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

    Thanks

    Jon

  • #2
    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.
    Last edited by Old Pedant; Aug 17, 2011, 10:04 PM.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      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

      Thanks

      Comment


      • #4
        The menu is working in IE under http://testing.makingtrails.com

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

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎