Files

28 lines
706 B
JavaScript

class ColorButtonsApp {
constructor(backgroundElement, statusElement) {
this.backgroundElement = backgroundElement;
this.statusElement = statusElement;
}
setColor(color) {
this.backgroundElement.style.backgroundColor = color;
this.statusElement.textContent = `Current background: ${color}`;
}
connectButton(button, color) {
button.addEventListener("click", () => this.setColor(color));
}
initialize() {
this.connectButton(document.getElementById("blueBtn"), "blue");
this.connectButton(document.getElementById("redBtn"), "red");
}
}
const application = new ColorButtonsApp(
document.body,
document.getElementById("status"),
);
application.initialize();