Working with the CSSstyleSheet API
- Changing the selectorText -

Test 2 - correcting script errors

The "Analize JS" option in the JS Panel of the CodePen is reporting that the "i" and "j" variables are missing a declaration as var (and a superfluous ";"). Changed the script in that way (see source code).
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