Home > Net >  How can i replace text and background color in wordpress?
How can i replace text and background color in wordpress?

Time:09-16

I want to change my website WordPress theme from light to dark mode. I want to use JS to make it much faster and easier. My question is, how can I replace the dark text color with white and the white background color with dark?

I can't add a tag to the classes, because I'm using elementor for WordPress.

I already have this code to change white backgrounds into dark ones, but how can I do that for fonts too?

(function () {
    if (window.getComputedStyle(document.body, null).getPropertyValue("background-color") == "rgb(255, 255, 255)") {
        console.log("Setting new background color...");
        document.body.setAttribute("style", "background-color: #121212;");
    }

})();

CodePudding user response:

With jQuery, You could set the background color and text color this way.

    $(document).ready(function(){
       $('body').css('background-color', '#121212');
       $('body').css('color', '#ffffff');
    });

CodePudding user response:

I don't recommend using * for global style changes other than the standard ones. However, if you really want to use this script. This takes precedence over inline styles and CSS styles containing the !important rule.

var all = document.getElementsByTagName("*");

for (var i = 0, max = all.length; i < max; i  ) {
  all[i].setAttribute('style', 'background-color: green !important; color: red !important;');
}
/* to demonstrate */

body {
  background: white !important;
}

div {
  color: blue;
}
<div style="color: blue;">i'm red? maybe?</div>

  • Related