Replacing Specific color code in css using jquery

前端 未结 5 1455
孤独总比滥情好
孤独总比滥情好 2020-12-19 04:10

I want to replace #789034 code to another code like #456780 where ever it finds in main.css using jquery

I am having a main.css file something like below :



        
5条回答
  •  执念已碎
    2020-12-19 04:28

    You can achieve this functionality by using CSS variables. Define a variable in your main.css file.

    :root {   
        --color1: #789034; 
    }
    

    and use this variable instead of color code.

    .common-color
    {
      color: var(--color1);
    }
    

    Now you can change the color by implementing the following function through passing new color in the parameter.

    function ChangeColor1(newColor)
    {
      document.documentElement.style.setProperty('--color1',newColor);
    }
    

提交回复
热议问题