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

96
Views
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 answers
Answer question

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 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!