我如何在svg类中获取属性

时间:2019-05-02 05:39:26

标签: jquery html

我想在svg类中获取该属性,但是它不起作用。

我正在使用Django,html,php,查询。

    <svg:path id="yui_patched_v3_18_1_1_1556774865622_2128" 
pointer-events="visiblePainted" shape-rendering="auto" width="206" height="267.5" x="0" y="0" fill="none" stroke-dasharray="none" 
stroke="#27aae1" stroke-linecap="butt" stroke-width="2" stroke-opacity="1" stroke-linejoin="round" transform="matrix(1,0,0,1,0,0)" style="left: 0px;
 top: 0px; visibility: visible;"
 class="yui3-shape yui3-svgShape yui3-path yui3-svgPath" 
d=" M103, 267.5C154.5,267.5 206, 228 206, 188.5">
</svg:path>

我尝试了以下操作,但不起作用。

$(".yui3-shape yui3-svgShape yui3-path yui3-svgPath").each(function(index, item){
        let temp = $(item).attr('s');
        console.log("edge"+temp);
    });

1 个答案:

答案 0 :(得分:3)

您选择了错误的选择器。如果要从一个选择器中选择多个类,则必须像这样添加它们:.yui3-shape.yui3-svgShape.yui3-path.yui3-svgPath

此外,您应该添加属性的正确名称:

$(".yui3-shape.yui3-svgShape.yui3-path.yui3-svgPath").each(function(index, item){
    let temp = $(item).attr('stroke'); // Here you can add attributename as per your requierments
    console.log("edge "+temp);
});