Referencing an empty node

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jeffmatthews
Forum Newbie
Posts: 10
Joined: Wed Oct 21, 2009 10:22 pm

Referencing an empty node

Post by jeffmatthews »

How to access?

1. This works: <name>Joe</name>

nameElement[0].firstChild.nodeValue returns "Joe"

2. This does not work: <name></name>

nameElement[0].firstChild.nodeValue creates an error.

I have tried using a boolean operator to evaluate it (if nameElement....), but that does not work, either.

So, how am I to ever figure out I have an empty text tag?
jeffmatthews
Forum Newbie
Posts: 10
Joined: Wed Oct 21, 2009 10:22 pm

Re: Referencing an empty node

Post by jeffmatthews »

Matt's a busy guy! :roll:

I found the answer. Must test: if (name[0].firstChild)...

What a joke! Who wrote the program to require such extraneous evaluations? It should just return null or an empty string, or whatever.
Post Reply