W3C home > Mailing lists > Public > www-svg@w3.org > October 2010

Re: SVG 1.1 Does no text exist in the DOM? or why no eggs?

From: Jeff Schiller <codedread@gmail.com>
Date: Sat, 2 Oct 2010 16:59:52 -0700
Message-ID: <AANLkTi=tbk7PybF+hwig4L8hxsAj4Kg4M9KrcRDKMF81@mail.gmail.com>
To: Jonathan Chetwynd <j.chetwynd@btinternet.com>
Cc: www-svg <www-svg@w3.org>
Hi Jonathan,

Apart from '2e' not being a valid variable name (variables cannot begin with
numbers), it looks like the textContent property is the way you want to do
this:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent

   <text id='foo'/>

   var foo = document.getElementById('foo');
   foo.textContent = 'foooooo';

As per the DOM spec, this creates a single text node and appends it.

To do it using 'nodeValue', you'd have to first create a text node:

  var someTextNode = document.createTextNode();

then set its nodeValue to the text

  someTextNode.nodeValue = 'foooooo';

then append the text node:

  foo.appendChild(aTextNode);

Obviously textContent is a nicer way to do this.

Regards,
Jeff

On Sat, Oct 2, 2010 at 2:44 PM, Jonathan Chetwynd <j.chetwynd@btinternet.com
> wrote:

> Does no text exist in the DOM? or why no eggs?
>
> <text></text> should to my way of  thinking provide a handle for script to
> enter  text into the DOM, but it doesn't in ff opera or safari,
> so why not?
> ie is there a specification that defines this behaviour?
> hard to file a bug, as I cant fathom this out.
>
> regards
>
> Jonathan Chetwynd
>
> in this testcase onmouseover, "ham'n" gets displayed, but no 'eggs'
>
> this  may likely be correct, but what is the benefit, or purpose?
> and what the workaround?
>
> please note that once instantiated, on can remove all the content, and add
> new content, but not apparently start with no content.
> not a very nice workaround.....
>
> <?xml version="1.0" encoding="utf-8" standalone="no"?>
> <svg xmlns="http://www.w3.org/2000/svg">
> <rect x="80" y="75" id="chat" width="45" height="36" fill="#cca"
> onmouseover="addText()" />
> <text id="chatText" x="83" y="90" > </text>
> <text id="chat2Text" x="83" y="105" ></text>
>
> <script type="text/ecmascript"> <![CDATA[
> function addText(){
>        e = document.getElementById("chatText");
>        e.firstChild.nodeValue='';
>        e.firstChild.nodeValue="ham'n";
>        2e = document.getElementById("chat2Text");
>        2e.firstChild.nodeValue='eggs';
> }
> ]]></script>
> </svg>
>
>
Received on Sunday, 3 October 2010 00:00:48 GMT

This archive was generated by hypermail 2.3.1 : Friday, 8 March 2013 15:54:46 GMT