Weird JS

Written in

by

A few days ago I found out that the following actually works.

HTML file:

<button id="hello">Say hello</button>

JavaScript file:

hello.onclick = function() {
  alert('Hello!');
}

Whaaat. The object is created using the element’s id.

Then I found out it’s a bad practice doing so. Oh well.