Sergomen
@Sergomen
Просто делай добро и оно вернётся

Что не так с созданием polyline?

Нужно через javascript создать polyline, я пишу:

<html>
	<head>
	</head>
	<body>
	<svg id="svg_lin" width="300px" height="39">
	 <polyline points=" 12 -2, 22  19.5, 12 39" class="spoiler_line" fill="none" stroke="black"/>

	</svg>
	<script>
	var svg_lin = document.getElementById('svg_lin');
	var pl = document.getElementsByClassName("spoiler_line");
	console.log(pl[0].points[0].x);
	<!-- Выводит:12. Впрочем как и должно быть -->
	
	var new_polyline=document.createElement('polyline');
	
	new_polyline.points[0].x = 22;
	new_polyline.points[0].y =-2;
	
	new_polyline.points[1].x = 32;
	new_polyline.points[1].y = 19.5;
	
	new_polyline.points[2].x = 22;
	new_polyline.points[2].y = 39;
	<!-- По идее это должо добавить points к  polyline -->
	
	svg_lin.appendChild(new_polyline);
	/*
	Но показывает ошыбку:
	Uncaught TypeError: Cannot read property '0' of undefined
    at i.html:17
	*/ 
	
	</script>
	</body>
	</html>

Но показывает ошибку:

Uncaught TypeError: Cannot read property '0' of undefined
    at i.html:17

Что не так?
  • Вопрос задан
  • 69 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы