Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Change html language with a button and save after refreshing the page

I was wondering how to save the html language on a website after reloading the page. I created a couple of language buttons, here's one example:

<a onclick="changeLang('pt')" href="#" title="Portugese" data-lang="Portugese">
   <div class="flag pt">Portugese</div>
</a>

And a bit of code in my JS file:

const changeLang = (languageCode) => {
  document.documentElement.setAttribute("lang", languageCode);
};

How can I make sure the language stays Portugese after clicking the button?

Thank you for your help in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are few option, in my opinion best approach is to have different url for different language (domain.com, domain.com/pt, domain.com/fr) which is good for SEO. You can also save language in cookie with javascript and then on page load fetch current language from cookie, check here how to set and fetch cookie.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!