When I run this Javascript code
var anchor = document.createElement("a");
anchor.style = "cursor:pointer;color:blue;";
anchor.onclick = "this.parentNode.parentNode.removeChild(this.parentNode);";
anchor.innerHTML = "remove";
div.appendChild(anchor);
My anchor is created as <a style="cursor: pointer; color: blue;">remove</a>
The onclick attribute is missing and the onclick function does not work.
Can I fix it?