I have to remove all the event listener that is added to document.
So according to THIS POST, I have built a function like this but it is showing TypeError: document.parentNode is null
!
var msg = document.getElementById('state-msg');
var button = document.getElementById('removeListener');
document.addEventListener('keydown', function(e) {
msg.textContent = 'keydown:' + e.keyCode;
});
document.addEventListener('keyup', function(e) {
msg.textContent = 'keyup:' + e.keyCode;
});
document.addEventListener('keypress', function(e) {
msg.textContent += 'keypress:' + e.keyCode;
});
button.addEventListener('click', function(e) {
var elClone = document.cloneNode(true);
document.parentNode.replaceChild(elClone, document);
});
Press any key and get the message here: <span id="state-msg"></span>
<button id = "removeListener">RemoveListener</button>
This can be very basic question but still, no success, Any kind of comment will be greatly appreciate.
UPDATE:
I also tried document = elNode
, but not working.