I am encountering an issue while trying to remove an event listener that was created inside a function. Oddly enough, it works perfectly when I move the event listener outside of the function. See the 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>