Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
Get cookie value by name and change style DOM element

Get cookie value by name and change style DOM element. I want to get the Arabic language from cookie and change the style of div to "dir=rtl" but I don't know I can do this in one function

   <h2 class="text">{% translate 'Admin' %}</h2>
       <form class="login-form" method="post">
             {% csrf_token %}
            <div class="login-form">
                  {% include 'form_login.html' with field=form.username %}
             </div>             
        </form>
</div>
<style>
Object.defineProperty(window, "Cookies", {
    get: function() {
        return document.cookie.split(';').reduce(function(cookies, cookie) {
            cookies[cookie.split("=")[0]] = unescape(cookie.split("=")[1]);
            return cookies
        }, {});                                                                         ```                                                                                           there I want to get language and if this is Arabic do change of class="login-form" to style dir="rtl"                                                                              ```
    }
});
</style>

Please how I can do this

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Image we have a cookie with language name and a div with myDiv id to change it's style to rtl if the language has set to arabic in the cookie:

<script>
function getCookie(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2){
      return parts.pop().split(';').shift();
   }
}
const isArabic = getCookie('language') === 'Arabic';
const myDiv = document.getElementById('myDiv')
if(isArabic){
  myDiv.dir = isArabic ? 'rtl' : 'ltr';
}
</script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda