I want to create a function that gets the ID of the element clicked. For example the button
<button id="test" onclick="getElementId();"> Test </button>
I thought about using this to get the function running
<script>
function getElementId(){
var x = document.getElementById(this).getAttribute('id');
}
</script>
But the console keeps saying "Uncaught TypeError: Cannot read properties of null (reading 'getAttribute') at getElementId ((Index):83:48) at HTMLButtonElement.onclick ((Index):80:52)"
I get, that this returns empty.