Changing scss variable in runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zack101
    New Member
    • Nov 2022
    • 1

    Changing scss variable in runtime

    Hi I have a variable on style-rtl.scss file : $language: var(--lang);

    and that variable got defined in the root on style.css :

    :root {

    --lang: 'selectedLang';

    }

    and in the main.js file:

    let language = localStorage.ge tItem("lang"); //ar/fr

    let r = document.queryS elector(':root' );

    let rs = getComputedStyl e(r);

    r.style.setProp erty('--lang', language);

    let result = rs.getPropertyV alue('--lang');

    console.log(res ult); // fr

    when i try to use this language variable on style-rtl.scss file it's read without problem :

    .element {

    content: $language;

    }

    But the problem is when I try to use it on if condition:

    .element {

    u/if $language == 'ar' {

    background-color: aqua;

    }@else if $language == 'fr' {

    background-color: red;

    }

    }
Working...