diff --git a/script.js b/script.js index d342434..b6aaf39 100644 --- a/script.js +++ b/script.js @@ -1,3 +1,16 @@ function update() { - document.getElementsByTagName('style')[0].innerHTML = document.getElementById("css-editor-textarea").value; -} \ No newline at end of file + const css = document.getElementById("css-editor-textarea").value; + const styleElements = document.getElementsByTagName("style"); + const length = styleElements.length; + + // If there is no style element, create one + if (length === 0) { + const styleElement = document.createElement("style"); + document.head.appendChild(styleElement); + } + + // Apply the CSS changes to all style elements + for (let i = 0; i < length; i++) { + styleElements[i].innerText = css; + } +}