I'm adding an event listener to my paragraph element in Javascript. My paragraphs are inside my 'main' HTML element. when the user presses the keyboard button 'AltGr' (key code 18) the paragraph is supposed to become a child of its predecessor. But the event itself isn't firing. Why is this and how do I solve the problem?
let m=document.getElementById('textEdit');
function pKeyClick(e){
if (e.keyCode=="18"){ //AltGr
e.preventDefault();
let parent=m.childNodes[m.childNodes.length-2];
let li=document.createElement("li");
m.replaceChild(li,e.target);
parent.appendChild(ul);
console.log(parent.childNodes)
e.stopPropagation();
}
}
The event gets attached whenever p is generated.