svg Polygon Points - Javascript - Not Working - Stack Overflow

How can I control the points of a svg polygon via JavaScript? Tried solving it this way, but it does no

How can I control the points of a svg polygon via JavaScript? Tried solving it this way, but it does not work.

function points() {
  document.getElementById("polygon").points = "0,100 0,0 100,100";
}
<svg width="100" height="100">
  <polygon id="polygon" points="0,0 100,0 100,100" style="fill:#000;">
</svg>
  
<input type="button" onClick="points" value="Change Polygon Points">

How can I control the points of a svg polygon via JavaScript? Tried solving it this way, but it does not work.

function points() {
  document.getElementById("polygon").points = "0,100 0,0 100,100";
}
<svg width="100" height="100">
  <polygon id="polygon" points="0,0 100,0 100,100" style="fill:#000;">
</svg>
  
<input type="button" onClick="points" value="Change Polygon Points">

Share Improve this question edited Sep 20, 2015 at 13:11 JakeTheSnake asked Sep 20, 2015 at 12:32 JakeTheSnakeJakeTheSnake 2,4643 gold badges16 silver badges27 bronze badges 1
  • That's basically the same polygon so you'd never know whether the function did anything. – Robert Longson Commented Sep 20, 2015 at 12:38
Add a ment  | 

2 Answers 2

Reset to default 4

I've changed the output polygon so that it looks different to the starting polygon, otherwise it looks like the code doesn't do anything.

function points() {
  document.getElementById("polygon").setAttribute("points", "100,0 50,0 100,100");
}
<svg width="100" height="100">
  <polygon id="polygon" points="0,0 100,0 100,100" style="fill:#000;">
</svg>
  
<input type="button" onClick="points()" value="Change Polygon Points">

document.getElementById('polygon1').setAttribute('points', '100, 0 50, 0 100, 100');

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744985291a4604574.html

相关推荐

  • svg Polygon Points - Javascript - Not Working - Stack Overflow

    How can I control the points of a svg polygon via JavaScript? Tried solving it this way, but it does no

    21小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信