I have a function that I want to execute relevant to the calling elements but I can't seem to the pass it as itself as a reference to the function I want to execute.
In short, this works
<div style="background-color:#444444">
<button onclick="this.parentElement.style.display = 'none';">close</button>
</div>
And this does not
<script>
function close() { this.parentElement.style.display = 'none'; }
</script>
<div style="background-color:#444444">
<button onclick="close()">close</button>
</div>
Why is this and is there a way around it?
document.getElementsByTagName("button")[0].addEventListener("click", close)