javascript - How to get the data value of 'SVG path'? -
i want extract info d="m75.5 299.5 111.5 299.5 111.5 311.5 75.5 311.5 z"
utilize in creation of element.
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="670px" height="400px" style="position: relative; display: block; background-color: red;"> <g> <path id="k19a56d40" data-model-id="k33d3f3bd" d="m75.5 299.5 111.5 299.5 111.5 311.5 75.5 311.5 z" stroke="#cc2900" stroke-width="1" stroke-linecap="square" stroke-linejoin="round" fill-opacity="1" stroke-opacity="1" fill="#ff3300"></path> <path id="k67a7e77a" data-model-id="k33d3f3bd" d="m75.5 299.5 111.5 299.5 111.5 311.5 75.5 311.5 z" stroke="#cc2900" stroke-width="1" stroke-linecap="square" stroke-linejoin="round" fill-opacity="1" stroke-opacity="1" fill="url(#kcd2b6a0)"></path> </g> </svg>
try this:
$('svg').find('path').attr('d');
find first 1 using .eq()
, .first()
:
$('svg').find('path').first().attr('d'); $('svg').find('path').eq(0).attr('d'); // <--change index of selection
.last()
can used if have 2 paths.
javascript jquery html svg
No comments:
Post a Comment