Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2002
    Location
    São Paulo, BRAZIL
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How can we get childNodes from a custom tag?

    Hello dudes, i wrote a very simple HTML page to test some DOM features between Mozilla and IE. Mozilla is perfect everything went fine and i got the childNodes from my custom tag ( this tag i named <blah> ), inside this tag there is two <span>, that i retrieved. But with IE i really could figure out how its done! Here is my test below, i´d glad if someone point me how it could be done for IE also.

    Regards,
    LottaLava

    <html>
    <head>
    <script language="JavaScript">
    function test( )
    {
    var obj = document.getElementsByTagName( "blah" );
    var span = null;

    for ( var i = 0; i < obj.length; i++ )
    {
    if ( obj[ i ] != null )
    {
    alert( obj[ i ].getAttribute( "name" ));

    for ( var j = 0; j < obj[ i ].childNodes.length; j++ )
    {
    span = obj[ i ].childNodes[ j ];

    if ( span.nodeName == "SPAN" )
    alert( span.getAttribute( "name" ));
    }
    }
    }
    }
    </script>
    </head>
    <body>
    <form name="frmMain"
    method="POST"
    action="http://localhost/blah">
    <span name="span01"><p>1</span><br>
    <span name="span02"><p>2</span><br>
    <blah name="tblBlah">
    <span name="span03"><p>3</span><br>
    <button type="button" name="btBlah" onClick="test( );">Test</button>
    <span name="span04"><p>4</span><br>
    </blah>
    </form>
    </body>
    </html>

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    When IE sees:

    <custom>hello world</custom>

    It represents it in the DOM like this:

    empty HTML tag: CUSTOM
    Text node: hello world
    empty HTML tag: /CUSTOM

    (they are all siblings), instead of the expected:

    HTML tag: CUSTOM --> Text node: hello world

    which is how Mozilla sees it.

    The solution is to rely upon IE's HTML Namespaces, which is kind of a weird thing, but whatever.

    In your <html> tag, include

    xmlns:my="http://www.mywebsite.com/my"

    Now, on custom tags, do:

    <my:custom> instead of just <custom>

    And that's it, parsing problem solved.


  •  

    Posting Permissions

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