let draw = document.createElement("svg"); draw.setAttribute('xmlns', 'http://www.w3.org/2000/xmlns/'); draw.setAttribute('version', '1.1'); draw.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink/'); draw.setAttribute('width', '500'); draw.setAttribute('height', '420'); game.append(draw); let tail = document.createElementNS("http://www.w3.org/2000/svg/", "polygon"); tail.setAttribute('points', '10,10 100,10 55,100'); tail.setAttribute('fill', 'orange'); tail.setAttribute('stroke', 'black'); tail.onclick = function(event) { alert('1'); }; draw.append(tail);