Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-26-2003, 01:40 PM   PM User | #1
LottaLava
New Coder

 
Join Date: Oct 2002
Location: São Paulo, BRAZIL
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
LottaLava is an unknown quantity at this point
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>
LottaLava is offline   Reply With Quote
Old 12-26-2003, 10:22 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:52 AM.


Advertisement
Log in to turn off these ads.