Question about some basic functions in SVG ECMAScript

R

RC

Sorry I couldn't find appropriate group for
SVG and ECMAScript. Since SVG is in XML format
and ECMAScript is very similar to JavaScript.
What's why I post in these two groups.

In the O'Reilly SVG book, in chapter 11
Animating and Scripting SVG. It mentions
some very basic functions like

var circle = event.getTarget();

var obj = svgDocument.getElementById("idName");

I got error message said these are no a function
in Firefox and batik-squiggle.jar

When I used SVGView plug-in (made by Adobe) for IE .

I typed:

var svgObject = evt.target;
var svgDoc = svgObject.getOwnerDocument();
var svgElement = svgDoc.getElementById(idName);
var svgStyle = svgElement.getStyle();
svgStyle.setProperty('stroke-width', 3);

These lines are working fine for SVGViwe Plug-in by
not work for Firefox and batik.
They complained that getOwnerDocument is not a function.
I tried to change getSVGDocument but no luck.

Is that O'Reilly book too old? Its first editoin is 2002.

How can I make getElementById() working in Firefox and Batik?
Is there some examles or some documents?
Thank Q very much in advance!
 
M

Martin Honnen

RC said:
var circle = event.getTarget();

var obj = svgDocument.getElementById("idName");
var svgObject = evt.target;
var svgDoc = svgObject.getOwnerDocument();
var svgElement = svgDoc.getElementById(idName);
var svgStyle = svgElement.getStyle();
svgStyle.setProperty('stroke-width', 3);

The ECMAScript binding for the DOM want you to use e.g.
event.target
svgObject.ownerDocument
svgElement.style
and not those getXXX variants you are using.
With the Adobe SVG viewer you can use both variants but for newer SVG
implementations you need the variants I have outlined above.
See also
<http://jwatt.org/svg/authoring/#asv-getters-and-setters>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top