Trying to Find the ParentNode

M

Michael Hill

I am trying to get all the "polyline" tags and then find the parent node
above it so I can transform it.

var poly = svgDocument.getElementsByTagName("polyline");
for ( var i=0; i < poly.length; i++ )
{
myobj=poly.parentNode(i);
alert(i + myobj);
}

This is not working. Any help is appreciated.

Mike
 
R

Richard Cornford

Michael Hill said:
I am trying to get all the "polyline" tags and then find the
parent node above it so I can transform it.

var poly = svgDocument.getElementsByTagName("polyline");

I haven't had much to do with scripting the SVG DOM yet, but:-
for ( var i=0; i < poly.length; i++ )
{
myobj=poly.parentNode(i);

In principal - poly - is a nodeList interface implementing object. In
JavaScript/ECMA Script it should be posible to access numerically
indexed members of a nodeList in the same way as an Array is accessed;-
poly - or using the nodeList's - item - method - poly.item(i) - .
That should return a reference to one of the "polyline" elements. It is
those elements that may/should have a parentNode property, not the
nodeList object.

The object that represents the parentNode (if any) would be another
element and almost certainly implemented as an object, not a function.
So calling that property and passing - i - as a parameter to that
function call doesn't make much sense. Probably you want something
like:-

myobj = poly.parentNode;

alert(i + myobj);

If - i - is an integer and - myobj - refers to an object what do you
expect to be the result of adding them together? You can type-convert
them to strings and get the - + - operator to do concatenation by adding
a string to that expression:-

alert( i + " " + myobj);

The result should also be clearer to read, as it will introduce a space
between them.
}

This is not working. Any help is appreciated.

"This is not working" is rarely sufficient information to allow anyone
to usefully comment on why something isn't working. You need, at the
very least, to provide a context (testing/execution environment(s)) for
it and some criteria for "working" and details of how failure to achieve
that is manifesting itself. Particularly important are any error
messages generated.

Richard.
 
J

Jim Ley

I haven't had much to do with scripting the SVG DOM yet, but:-

It's nice! You've got DOM 2,
JScript, JavaScript (both rhino and spidermonkey) and KJS are all
used by good SVG user agents, although it's a time when using the
Compact Profile (ECMA 327 is it? - this could be FAQ'd actually?) as
there are a lot of scriptable mobile user agents.

There is an old SVG browser (ASV 2 in NN4) that doesn't have try/catch
but all others do and you're probably safe to use it.
myobj = poly.parentNode;


Yep!

Jim.
 
R

Richard Cornford

It's nice! You've got DOM 2, JScript, JavaScript
(both rhino and spidermonkey) and KJS are all used
by good SVG user agents, although it's a time when
using the Compact Profile (ECMA 327 is it? - this
could be FAQ'd actually?) as there are a lot of
scriptable mobile user agents.
<snip>

Yes, ECMA 327 is the Compact Profile and it probably does deserve a
mention in the FAQ. Especially as it is only two pages on the features
from ECMA 262 that do not need to be implemented in the Compact Profile.

Richard.
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top