I'm doing a multilingual page for practice, and i would like add line brake in to the text what i display. What could be a solution. I tried \n
and <br>
too.
Here is my code:
var arrLang = {
"en": {
"text": "See Budapest, the Queen of the Danube from brand new perspective as you have never seen before!"
},
"ger": {
"text": "Nézd meg Budapestet,"
}
};
var lang = "en";
if('localStorage' in window){
var usrLang = localStorage.getItem('uiLang');
if(usrLang) {
lang = usrLang
}
}
$(document).ready(function() {
$(".lang").each(function(index, element) {
$(this).text(arrLang[lang][$(this).attr("key")]);
});
});
$(".translate").click(function() {
var lang = $(this).attr("id");
// update localStorage key
if('localStorage' in window){
localStorage.setItem('uiLang', lang);
console.log( localStorage.getItem('uiLang') );
}
$(".lang").each(function(index, element) {
$(this).text(arrLang[lang][$(this).attr("key")]);
});
});
p {
height: 150px;
width: 380px;
background-color: grey;
text-align:center
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<a href="" id="en" class="translate">English</a>
<a href="" id="ger" class="translate">German</a>
<p class="lang" key="text">
Lorem ipsum dolor sit amet <br> consectetur, adipisicing elit. <br>
Ut hic amet eius soluta exercitationem <br>
sunt et ad in, aspernatur at. <br>
Facere voluptatem quasi, enim <br>
</p>
</div>
Thank you for your help.