JavaScript
0
Вклад в тег
<body>
<div class="lang df">
<button value="en" class="active" id="lang-en">EN</button>
<button value="ru" id="lang-ru">RU</button>
</div>
<div class="title">
<h1 class="lng-h1">Text</h1>
<button class="btn lng-btn">Learn more</button>
</div>
<script src="app.js"></script>
</body>
const langArr = {
h1: {
en: 'Text',
ru: 'Teкст',
},
btn: {
en: 'Learn more',
ru: 'Узнать больше',
},
};
document
.querySelectorAll('.lang button')
.forEach((b) => b.addEventListener('click', setLang));
function setLang() {
for (let key in langArr) {
let elem = document.querySelector('.lng-' + key);
if (elem) {
elem.innerHTML = langArr[key][this.value];
}
}
}