最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing properties of SVG circle in HTML5JS - Stack Overflow

programmeradmin0浏览0评论

I'm trying to make a very simple modification of a circle SVG. The script code should change the radius of the circle, but nothing seems to happen. (using the same format, I am able to change the color but none of the other elements of the circle).

<!DOCTYPE html>
<html>
    <body>
        <svg xmlns="">
            <circle cx="100" cy="100" r="50" fill="red" id="cir"/>
        </svg>

        <script>
            document.getElementById("cir").r = 2000;
        </script>
    </body>

</html>

I'm trying to make a very simple modification of a circle SVG. The script code should change the radius of the circle, but nothing seems to happen. (using the same format, I am able to change the color but none of the other elements of the circle).

<!DOCTYPE html>
<html>
    <body>
        <svg xmlns="http://www.w3.org/2000/svg">
            <circle cx="100" cy="100" r="50" fill="red" id="cir"/>
        </svg>

        <script>
            document.getElementById("cir").r = 2000;
        </script>
    </body>

</html>
Share Improve this question asked Jul 29, 2014 at 21:18 KennethKenneth 1,0551 gold badge12 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 17

"r" is no property of the element, it's an attribute. Use this:

document.getElementById("cir").setAttribute("r", 2000);
发布评论

评论列表(0)

  1. 暂无评论