Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comments in svg path

Tags:

svg

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.

like image 396
dr jerry Avatar asked Sep 03 '25 05:09

dr jerry


1 Answers

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)

like image 125
Matti Virkkunen Avatar answered Sep 04 '25 23:09

Matti Virkkunen