html
<a href="#" data-lang="de">Deutsch</a>
<a href="#" data-lang="fr">Français</a>
js
let anchors = document.querySelectorAll('a');
for (let anchor of anchors) {
anchor.addEventListener("click", (event) => {
let langValue = event.target.getAttribute('data-lang');
setCookie("language-selected", langValue, 1); // expiration time is 1 day
})
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}