Working with the CSSstyleSheet API
- Changing the selectorText -

Test 3 - correcting script leaks

New vanilla javascript. - The for...of... statement is not supported by IE-11 (see MDN compatibility list), so I replaced it by a plain old for loop. To call the selectorText it seems not needed to stringify it (the MDN description says that the syntax of a CSSRule.selectorText is a string by itself), so I omitted it. Also applied some JSLint suggestions.
See what happens!

Testing a style update

  1. Use the Developer Tool of the browser and go to the 2nd <style> block in the <head>.
  2. Click right and "Edit as HTML".
  3. Delete the word main of the selector rule  main code { ... }
  4. Delete the whole style rule .testbox-1 { background: turquoise; color: black } and leave the editor by clicking somewhere in the Developer Pane outside the editor box.
  5. Then use the button to update the selectorText via the CSSStyleSheet API.

This is ".testbox1"This is ".testbox2"

The initial selectorText for each style rule of the 2nd style block is:

*
main code
.testbox1
.testbox2

The updated selectorText for each style rule of the 2nd style block is:

*
code
.otherClass
 

Results

Conclusions