I'm trying to remove an event listener that was created inside of a function, but for some reason, it isn't working. It works fine if I take it out of the function. Example below:
<body>
<div id='myDiv'></div>
<button type='submit' onclick='rel()'>RemoveEventListener</button>
<script>
function Mouse() {
myDiv.addEventListener('click', cK);
function cK() {
alert('You've clicked on myDiv!');
}
}
function rel() {
myDiv.removeEventListener('click', cK);
}
Mouse();
</script>
</body>
myDivcomponent? Do you use same ref for removing?id='myDiv'corresponding HTMLElement gets exposed as global variable.