I need to replace texts on multiple pages by clicking a simple button. What is the leanest switch between two languages?
var text1=document.getElementById(‘english’);
var text2=document.getElementById(‘swedish’);
const swap = () => {
if(english.classList.contains("hidden")){ //if english contains class 'hidden'
english.classList.remove("hidden"); //remove hidden class from english
swedish.classList.add("hidden"); //add hidden class to swedish
}
else{
english.classList.add("hidden"); //add hidden class to english
swedish.classList.remove("hidden"); //remove hidden class from swedish
}
}
.hidden{
display:none;
}
<button onclick="swap()">Switch Text</button>
<div class="content">
<div id=“english>
<h1>Welcome</h1>
<p>English text</p>
</div>
<div id=“swedish” class="hidden">
<h1>Vällkommen</h1>
<p>Swedish text</p>
</div>
</div>
this only changes text in the first div. I need to have language change applied across the site.