JSFiddle - React, Tailwind, and code Playground
by Руслан Абсалямов
HTML
<div class="day">
<h1>Привет зрителям LoftBloh</h1>
<button id ="day">День</button>
<button id ="night">Ночь</button>
</div>
CSS
.night{
color: white;
background-color: black;
}
.day{
color: black;
background-color: white;
}
JavaScript
(function() {
let buttons = document.getElementsByTagName('button');
for (let i = 0, len = buttons.length; i < len; i++) {
console.log(buttons[i])
buttons[i].onclick = function(){
if (this.id === 'day') {
document.body.className = 'day';
} else if (this.id === 'night') {
document.body.className = 'night'
}
};
};
})();
window.onbeforeunload = function() {
return "Данные не сохранены. Точно перейти?";
};