Files

21 lines
484 B
JavaScript
Raw Permalink Normal View History

class ColorButtonController {
constructor(buttonId, color) {
this.button = document.getElementById(buttonId);
this.color = color;
}
changeBackground() {
document.body.style.backgroundColor = this.color;
}
bind() {
this.button.addEventListener("click", () => this.changeBackground());
}
}
const blueButton = new ColorButtonController("blueBtn", "blue");
const redButton = new ColorButtonController("redBtn", "red");
blueButton.bind();
redButton.bind();