SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Small issue with document.getElementsByTagName

    Since I found myself typing out document.getElementsByTagName a lot, I decided to make a Prototype-style function to make it easier:
    Code:
    function $t(e) {
      return document.getElementsByTagName(e);
    }
    To use like this, for instance:
    Code:
    var whatever = $t('body')[0].className;
    Firefox doesn't complain but IE6 does, even though any code that uses it works as expected. IE6 throws the "'null' is null or not an object" error. I'm mystified by this. Can anyone shed any light on this please?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you trying to access html elements before the page has loaded?

    Post the simplest example that you can come up with that demonstrates your problem.

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I'm a tool. I was trying out thickbox, which uses a JS library called jQuery, and my own $ function (not the one I posted above) was conflicting with the one in jQuery:
    Code:
    function $(e) {
      return document.getElementById(e);
    }
    I got rid of jQuery and IE doesn't go berserk now. IE's weird and wrong reporting of what line number the error is on just served to add to my confusion.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE's weird and wrong reporting of what line number the error is on just served to add to my confusion.
    I find that sometimes a browser will report a filename and line number where the error occurred--but the filename is different than the one I'm currently working on. So I assume the line number is in the current file, which can be bewildering--especially when you chop out half the code and the reported error still has the same line number. Could that be what you are seeing?

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's exactly what happened to me too - I kept removing code and it just wouldn't change. Firefox always reports the line number correctly, but IE6's JS error reporting is utter rubbish.

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but IE6's JS error reporting is utter rubbish.
    I've never had any problems with it except for those cases where I misread the filename where the error occurred.

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But it doesn't tell you the filename... it tells you the page the error is on but not which .js file. if you have more than one JS file or some embedded in the head then it can get quite confusing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •