Trying to Find the ParentNode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Hill

    Trying to Find the ParentNode

    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.get ElementsByTagNa me("polyline") ;
    for ( var i=0; i < poly.length; i++ )
    {
    myobj=poly.pare ntNode(i);
    alert(i + myobj);
    }

    This is not working. Any help is appreciated.

    Mike

  • Richard Cornford

    #2
    Re: Trying to Find the ParentNode

    "Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
    news:40060A20.1 98846F8@ram.lmt as.lmco.com...[color=blue]
    >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.get ElementsByTagNa me("polyline") ;[/color]

    I haven't had much to do with scripting the SVG DOM yet, but:-
    [color=blue]
    > for ( var i=0; i < poly.length; i++ )
    > {
    > myobj=poly.pare ntNode(i);[/color]

    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[i] - 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[i].parentNode;

    [color=blue]
    > alert(i + myobj);[/color]

    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.
    [color=blue]
    > }
    >
    >This is not working. Any help is appreciated.[/color]

    "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.


    Comment

    • Jim Ley

      #3
      Re: Trying to Find the ParentNode

      On Thu, 15 Jan 2004 04:47:12 -0000, "Richard Cornford"
      <Richard@litote s.demon.co.uk> wrote:
      [color=blue]
      >"Michael Hill" <hillmw@ram.lmt as.lmco.com> wrote in message
      >news:40060A20. 198846F8@ram.lm tas.lmco.com...[color=green]
      >>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.get ElementsByTagNa me("polyline") ;[/color]
      >
      >I haven't had much to do with scripting the SVG DOM yet, but:-[/color]

      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.
      [color=blue]
      >myobj = poly[i].parentNode;[/color]

      Yep!

      Jim.
      --
      comp.lang.javas cript FAQ - http://jibbering.com/faq/

      Comment

      • Richard Cornford

        #4
        Re: Trying to Find the ParentNode

        "Jim Ley" <jim@jibbering. com> wrote in message
        news:40087089.2 0168420@news.ci s.dfn.de...
        <snip>[color=blue][color=green]
        >>I haven't had much to do with scripting the SVG DOM yet, but:-[/color]
        >
        >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.[/color]
        <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.


        Comment

        Working...