-1

Hey I would like to know how to change a CSS value of the document & not from a specific element

I alredy checked Change :hover CSS properties with JavaScript but the solution adds CSS rules. I've read this too https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle but targets a specific element too...

I would like to change a value that has been declared in the css file, some kind of an 'absolute value'

It might be something like (we'll here change color of a tag) :

var sheet = document.getStyle();
sheet.getTagStyle('a').getProperty('color').setValue('rgb(0,0,0)');

(The solution must anyway be in https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle but I don't get it)

So, is this kind of thing possible, and if yes how? (Beware in js not jquery please)

1 Answers1

0

Iterate document.styleSheets, check if .selectorText of .cssRules matches selector, set .style of .cssRules

for (let {cssRules} of document.styleSheets) {
  let [{selectorText, style}] = cssRules;
  if (selectorText === "a") {
    style.color = "rgb(0, 0, 0)";
  }
}
a {
  color: rgb(122, 125, 22);
}
<a>123</a>
guest271314
  • 1
  • 15
  • 104
  • 177