Javascript 如何获取';SVG路径';?

Javascript 如何获取';SVG路径';?,javascript,jquery,html,svg,Javascript,Jquery,Html,Svg,我想提取数据d=“M75.5 299.5 111.5 299.5 111.5 311.5 75.5 311.5 z”以在创建另一个元素时使用它 <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="670px" height="400px" style="position: relative; display: block; background-color: red;"> <g>

我想提取数据
d=“M75.5 299.5 111.5 299.5 111.5 311.5 75.5 311.5 z”
以在创建另一个元素时使用它

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

使用以下方法:

$("#k19a56d40").attr("d");
试试这个:

$('svg').find('path').attr('d');
使用
.eq()
.first()
查找第一个:

$('svg').find('path').first().attr('d');
$('svg').find('path').eq(0).attr('d');// 纯JavaScript

function(pathElemId){
var path=document.getElementById(pathElemId);
return path.getAttribute("d")
}
此函数为具有pathElemId的path元素返回“d”

function(pathElemId){
var path=document.getElementById(pathElemId);
return path.getAttribute("d")
}