CSSStyleRule-set-selectorText.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <!DOCTYPE html>
  2. <style id="styleElement">
  3. .green-background { background-color: rgb(0, 255, 0) !important; }
  4. .red-background { background-color: rgb(255, 0, 0); }
  5. </style>
  6. <script src="../include.js"></script>
  7. <iframe id="iframe"></iframe>
  8. <script>
  9. function testSetSelectorText(doc) {
  10. const divElement = doc.createElement("div");
  11. divElement.classList.add("red-background");
  12. divElement.id = "container";
  13. divElement.innerHTML = "This shouldn't be visible";
  14. doc.body.appendChild(divElement);
  15. const divStyle = getComputedStyle(divElement);
  16. const greenBackgroundRule = doc.styleSheets[0].cssRules[0];
  17. println(`selectorText initial value: ${greenBackgroundRule.selectorText}`);
  18. println(`container element backgroundColor initial value: ${divStyle.backgroundColor}`);
  19. greenBackgroundRule.selectorText = "#container";
  20. println(`selectorText after setting selectorText value to #container: ${greenBackgroundRule.selectorText}`);
  21. println(`container element backgroundColor after setting selectorText value to #container: ${divStyle.backgroundColor}`);
  22. doc.body.removeChild(divElement);
  23. }
  24. test(() => {
  25. const frameDocument = document.getElementById("iframe").contentDocument;
  26. frameDocument.body.appendChild(document.getElementById("styleElement").cloneNode(true));
  27. println("Testing window.document:");
  28. testSetSelectorText(document);
  29. println("Testing iframe.contentDocument:");
  30. testSetSelectorText(frameDocument);
  31. });
  32. </script>