Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28495
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: short script -- what is wrong? |
| Date | 2015-08-04 11:19 +0200 |
| Organization | Liberty Development |
| Message-ID | <mpq03r$kfb$1@adenine.netfront.net> (permalink) |
| References | <103306d5-085e-41c7-950a-fcf3edfcd430@googlegroups.com> |
Jay Braun wrote:
> Here is a short trivial svg document that correctly displays a red square with a green border on a blue background. (The original script drew the red square and all other shapes with a "path" element):
>
> <?xml version="1.0" standalone="no"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
> "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
> <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="2188.000000pt" height="1312.000000pt" viewBox="0 0 2188.000000 1312.000000" preserveAspectRatio="xMidYMid meet">
> <g transform="translate(0.000000,1312.000000) scale(0.100000,-0.100000)"
> stroke="none">
> <rect width="999999999" height="999999999" style="fill: blue" />
> <path fill="red" stroke="green" stroke-width="100" d="M 10000 7000 l 0 1600 l 1600 0 l 0 -1600 l -1600 0 z" />
> </g>
> </svg>
>
> In my application, I will need to create and update several squares and other shapes over time. So I will need a script. I tried the following to try scripting the single red square, but nothing displays. Note that I have added id and onload attributes to the svg element:
>
> <?xml version="1.0" standalone="no"?>
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
> "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
> <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="2188.000000pt" height="1312.000000pt" viewBox="0 0 2188.000000 1312.000000" preserveAspectRatio="xMidYMid meet" iid="bigbox" onload="init()" >
> <g transform="translate(0.000000,1312.000000) scale(0.100000,-0.100000)"
> stroke="none">
> <rect width="999999999" height="999999999" style="fill: blue" />
>
> <script type="application/ecmascript">
> function init() {
> var bigbox=document.getElementById("bigbox");
> var ns="http://www.w3.org/2000/svg";
>
> var p=document.createElementNS(ns,"path");
> p.setAttribute("fill", "red");
> p.setAttribute("stroke", "green");
> p.setAttribute("stroke-width", "100");
> p.setAttribute("d", "M 10000 7000 l 0 1600 l 1600 0 l 0 -1600 l -1600 0 z");
> bigbox.appendChild(p);
>
> }
> </script>
>
> </g>
> </svg>
>
> I suspect that my error(s) will be obvious to the experts here. Thanks,
Well
iid="bigbox"
should be
id="bigbox"
I think.
But I suspect you want to add the created "path" element to the group
"g" in your document so I would put an id attribute on that "g" element
and call document.getElementById("myGId").appendChild(p);
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
short script -- what is wrong? Jay Braun <lyngwyst@gmail.com> - 2015-08-03 20:02 -0700
Re: short script -- what is wrong? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-08-04 11:17 +0200
Re: short script -- what is wrong? Martin Honnen <mahotrash@yahoo.de> - 2015-08-04 11:19 +0200
Re: short script -- what is wrong? Jay Braun <lyngwyst@gmail.com> - 2015-08-04 05:35 -0700
Re: short script -- what is wrong? Jay Braun <lyngwyst@gmail.com> - 2015-08-04 06:00 -0700
Re: short script -- what is wrong? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-08-04 15:20 +0200
Re: short script -- what is wrong? Jay Braun <lyngwyst@gmail.com> - 2015-08-04 06:45 -0700
Re: short script -- what is wrong? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-08-04 15:59 +0200
csiph-web