...

View Full Version : How can we get childNodes from a custom tag?



LottaLava
12-26-2003, 01:40 PM
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>

jkd
12-26-2003, 10:22 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum