When using event handler content attributes in HTML, according to the specification, the value of this
in the callback refers to the event's currentTarget
property (the input
DOM element in the example below). To access one of the DOM element's attributes, this can be done as follows:
<input type="text" onclick="console.log(this.type)"><!-- logs "text" -->
However, when writing an answer to another question, I somewhat unexpectedly found out that it's possible to refer to the element's properties using their unqualified property names. The following has been tested in current versions of both Chrome and Firefox:
<input type="text" onclick="console.log(type)"><!-- logs "text" -->
<input type="text" onclick="console.log(required)"><!-- logs "false" -->
<input type="text" onclick="console.log(tagName)"><!-- logs "INPUT" -->
Now, my question is: is this behavior specified somewhere? I don't seem to find anything in the HTML specification or the DOM UI events specification, and my Google searches are also turning up empty.