tags:

views:

90

answers:

1

I'm experimenting with jquery and svg, I make up my path but now I want to change that (based on some user input) I do something like

    var dpath = $('path').attr("d");
    $('path').attr("d",dpath.replace("150 150", "450 450"));

which works fine, but this not useful when my path grows, so I wonder is there a possibility to put a label or a comment in the path to serve as a replace hook? searching for "svg path comments" gives me all entries in forums with 'comments', which is not very useful. I'm close to write my own "replaceble" pseudo svg path code, but is there an alternative possible in svg? regards, Jeroen.

+1  A: 

SVG has an interface to the unserialized form of the path elements. Its description is in the SVG spec. You should be able to extend the objects by adding your own properties to serve as markers.

I've never used the interface, but you should be able to access a list of the path segments by using the pathSegList property (defined in SVGAnimatedPathData) by doing something along the lines of $("path")[0].pathSegList (the [0] is there to get to the actual DOM element instead of the jQuery object)

Matti Virkkunen
Check http://dev.w3.org/SVG/profiles/1.1F2/test/svg/paths-dom-02-f.svg for an example.
Erik Dahlström