parentNode Not Implemented?!?

Discussion in 'Javascript' started by DanielLinn@freightliner.com, Aug 8, 2006.

  1. Guest

    I'm getting an error in IE 6.0.2800 that says "Error: Not implemented."
    when I try to get a parent. Does it whether or not 'compatibility
    mode' is on.

    Here's my code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>User Results</title>
    <link href="css/screen.css" rel="stylesheet" media="all" />
    <script type="text/javascript" language="javascript">
    function highlightRow(elem) {
    alert(elem.parentNode.parentNode.id);
    parent = findOwner( elem );
    parent.className = "highlighted";
    }
    function findOwner( elem )
    {
    var node = elem;
    while (node)
    {
    if ( node.nodeType == node.ELEMENT_NODE && node.nodeName == "TR")
    {
    alert("found it");
    return node;
    }
    node = node.parentNode;
    }
    alert("didn't find it");
    return null;
    }
    </script>
    </head>
    <body>
    <table cellspacing="0" id="scrollMe" class="formdata">
    <tr id="rowThing">
    <td class="center command" id="tdThing"><input id="testingThis"
    type="checkbox" class="checkEm" name="vehIndex_0"
    onclick="highlightRow(this);" value="0"/>
    </td>
    </tr>
    </table>
    </body>
    </html>

    What's odd is that the first alert will return the proper ID of the row
    (using parentNode), but when I use parentNode to assign the parent to a
    var, it chokes. Works fine on Moz (surprise, surprise). Any ideas?
     
    , Aug 8, 2006
    #1
    1. Advertising

  2. RobG Guest

    wrote:
    > I'm getting an error in IE 6.0.2800 that says "Error: Not implemented."
    > when I try to get a parent. Does it whether or not 'compatibility
    > mode' is on.


    Because that is irrelevant to the error :)

    >
    > Here's my code:
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


    It is pointless to try using XHTML with IE, it will treat it as HTML
    anyway. Stick to 4.01 strict unless you have some really special
    reason to use XHTML, in which case IE becomes irrelevant.


    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head>
    > <title>User Results</title>
    > <link href="css/screen.css" rel="stylesheet" media="all" />
    > <script type="text/javascript" language="javascript">


    The language attribute is long since deprecated, just remove it.


    > function highlightRow(elem) {
    > alert(elem.parentNode.parentNode.id);
    > parent = findOwner( elem );


    Here you create 'parent' as a global variable, but not until
    higlightRow is executed. This is what is actually causing your problem
    - IE will not assign the result if the right hand side expression to
    it. You can declare parent anywhere - either global or local, local is
    better unless you have a reason for it to be global - and your issue
    goes away.


    > parent.className = "highlighted";


    Since findOwner can return null if a TR isn't found, you should test
    the returned value - what is the effect of adding a className property
    to the null object?


    > }
    > function findOwner( elem )
    > {
    > var node = elem;
    > while (node)
    > {
    > if ( node.nodeType == node.ELEMENT_NODE && node.nodeName == "TR")


    I can't understand why you bother with the first test - it creates a
    dependency on DOM 3 that doesn't seem necessary and is not supported by
    my IE 6 - it never finds the TR. Go back to HTML and DOM 2.

    If you want this to work on the web, just test the node name since it
    is sufficient for your purpose and much more widely supported.

    Since you are pretending to use XHTML, you should follow the advice in
    the W3C specs and compare node names (and tag names too for that
    matter) using lower case:

    if (node.nodeName && node.nodeName.toLowerCase() == 'tr' ){
    /* found an HTML TR node */
    }


    [...]

    > var, it chokes. Works fine on Moz (surprise, surprise). Any ideas?


    Not really a surprise that it works in Mozilla, which has much better
    support for DOM 3 than IE.

    What you are seeing is likely a bug in IE that it doesn't correctly
    assign a value to 'parent' - since it never finds the TR element, it
    should be assigned 'null' (maybe you are using IE 7 and it does support
    it, I dunno).


    --
    Rob
     
    RobG, Aug 9, 2006
    #2
    1. Advertising

  3. Guest

    Holy geez. That's the most complete and helpful response to a post
    I've ever had. Thanks for your help Rob. Now i'm going to go sulk in
    the corner and read the standards again ;)
     
    , Aug 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    3,474
  2. NotGiven
    Replies:
    0
    Views:
    525
    NotGiven
    Sep 17, 2004
  3. RC
    Replies:
    1
    Views:
    1,329
    Martin Honnen
    May 31, 2007
  4. Replies:
    3
    Views:
    127
  5. webdeveloper
    Replies:
    4
    Views:
    188
    webdeveloper
    Nov 21, 2006
Loading...

Share This Page