Given this code:
<button id="blah" onclick="alert(id)">Click me</button>
Clicking the button will alert "blah". Why does the id
attribute become a variable visible within the scope of the onclick
handler?
Another example:
<button style="font-size:200%" onclick="console.log(style)">Click me</button>
Here we see that style
refers to a CSSStyleDeclaration
object, rather than the string value of the attribute. This is similar to what we'd get by referencing an index of the button element's attributes
property, or through attribute properties like this.style
(getAttribute
would return the string value instead).
Where is this behavior specified?