lundi 4 octobre 2021

Is there a programmatic way to check whether specific CSS rules are valid or respected by the browser, or it is discarded / less specific?

In other words, I am looking for a way in JS to inspect or check current state of CSS rules dynamically at runtime (using browser's reflection feature, possibly) instead of only relying for browser developer's tool to see which rules are "overriden" or filtered. To think an analogy in procedural languages, there's normally a way to check the status or result of a statement or instruction (e.g true/false).

.mybutton#submit {
  color: red;
}
.mybutton {
  color: blue;
}
var sheet = document.styleSheets[0];
var rules = sheet.cssRules || sheet.rules;
is_valid(rules[0]); //True
is_valid(rules[1]); //False




Aucun commentaire:

Enregistrer un commentaire