Is it possible to know which element in the HTML is responsible for the action causing the error in JavaScript?
code:
<button onclick="a(this);">GO!</button>
<script>
window.onerror = function(message, source, lineno, colno, error) {
console.log(error.stack); // event.target = window
}
</script>
Output:
ReferenceError: a is not defined
at HTMLButtonElement.onclick (onerror.html: 1)
In this reference "HTMLButtonElement.onclick" says it's a button and it was in the onclick event, but at the same time it says nothing, I'm not able to select this element in any way, or in this way, using stack
it's not possible? Would there be another way to "get" this element?
var domID = "HTMLButtonElement".id;
addObjLog(document.querySelector(domID)); //exemplo de uso