Alexis Tyler Alexis Tyler - 1 month ago 6
HTML Question

What is it called when I can select a HTML element in JS using it's ID?

I've noticed that I can use

a
to reference an element with an ID of "a" but I'm not sure if there's a name for this "method".

For example this would set the div's text to "b c".

<div id="a" class="b c"></div>
<script>a.innerHTML = a.classList</script>

Answer

It seems to be called Named access on the Window object by HTML5 standard. Read more here

The HTML5 standard specifies that the window object must have a property key whose value is elem if...

there is exactly one DOM element elem whose property id has the value key.

there is exactly one DOM element elem whose property name has the value key. elem’s tag must be one of: a, applet, area, embed, form, frame, frameset, iframe, img, object.