// jshint esversion: 6
let $ = function(sel) {
return document.querySelector(sel);
};
//1. One Ring to Rule Them All
var main = function() {
//this keyword is set to the button that fired the event
console.log(this.id);
//dispatch on button id
if (this.id == "btn1")
$("div").innerHTML = "You clicked Button 1";
else if (this.id == "btn2")
$("div").innerHTML = "You clicked Button 2";
else if (this.id == "btn3")
$("div").innerHTML = "You clicked Button 3";
};
//2. register the onclick handlers after the DOM is complete
window.addEventListener("load", function() {
//select the buttons
var buttons = document.querySelectorAll("button");
//register the same handler for each button
for (var i = 0; i < buttons.length; ++i) {
buttons[i].addEventListener("click", main);
}
});