Re: why does <text/> have no firstChild with value ""

Hi Jonathan

This is definitely a DOM issue.
In a DOM document, everything is a node (Element, Text, comment, etc.) and
everything is *explicit*. If there is no text inside an element so there is
no text node in the DOM representation of the document.

So if you want to access a node that does not exist, you have to create it
and insert it first.

firstChild is a DOM API (A DOM Element attribut which is readonly) to access
the first child of an element IF IT EXISTS.

To simplify the use of DOM there are several discussion about short hand API
such as innerHTML (
http://www.w3.org/TR/html5/embedded-content-0.html#innerhtml) for HTML
document or textContent in a general DOM approach (
http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent)

You really should post that use case on the W3C WebApps WG (formerly DOM WG)
mailing list : www-dom@w3.org (I cross post it this e-mail so some clever
guy than I could answer you)

Regards,
Jeremie


2010/10/3 Jonathan Chetwynd <j.chetwynd@btinternet.com>

> why does <text/> have no firstChild with value ""
>
> Can someone please point me to an explanation why the authors inclusion of
> an empty text element does not generate a firstChild with value the empty
> string?
> my issue is that the current methodology requires additional coding and
> complication for the author, and little or no benefit to the UA, afaict.
>
> regards
>
> Jonathan Chetwynd
>
>
> A couple of kindly respondents provided excellent responses offline to my
> original post:
>
> Re: SVG 1.1 Does no text exist in the DOM? or why no eggs?
>
> but I hope this version may be a little clearer.
>
>
>
>


-- 
Jeremie
.............................
Web : http://jeremie.patonnier.net
Twitter : @JeremiePat <http://twitter.com/JeremiePat>

Received on Sunday, 3 October 2010 16:11:17 UTC