I recently learned that you could refer to an element in the DOM by directly using its id as a variable instead of using something like document.getElementById
.
Example:
<!-- the paragraph will end up saying "other text" -->
<p id="uniqueid">text</p>
<script>
uniqueid.innerHTML = "other text";
</script>
Other than that you can never access an id that falls outside of JavaScript's naming conventions, what are some cons to this method of accessing elements? I'm especially curious since I've never seen this before and I'm thinking that it's maybe for a good reason?