# content-blocks-builder/trunk/src/utils/editor.js

Content Blocks Builder – Create blocks, repeater blocks with carousel, grid, popup layouts, version trunk. 46 lines.

- Page: https://pluginprobe.com/plugins/content-blocks-builder/trunk/code/src/utils/editor.js
- Raw: https://pluginprobe.com/plugins/content-blocks-builder/trunk/raw/src/utils/editor.js
- Modified: 2026-08-05T07:16:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/content-blocks-builder/trunk/code/src/utils/editor.js#L10-L20`.

```javascript
/**
 * Get the owner document (considering editor iframe).
 *
 * @param {Document} document
 * @returns {Document}
 */
export const getDocument = (document) => {
  let previewDoc = document;

  const editorCanvas = document.querySelector('iframe[name="editor-canvas"]');
  if (editorCanvas) {
    previewDoc = editorCanvas.contentWindow.document;
  }

  return previewDoc;
};

/**
 * Update live-style
 *
 * @param {String} id
 * @param {String} content
 * @param {Boolean} remove
 */
export const updateDynamicStyle = (id, content, remove = false) => {
  let previewDoc = getDocument(document);

  let styleElement = previewDoc.getElementById(id);

  if (remove) {
    if (styleElement) {
      styleElement.remove();
    }
  } else {
    // Create a new one if don't have one
    if (!styleElement) {
      styleElement = previewDoc.createElement("style");
      styleElement.id = id;

      previewDoc.head.appendChild(styleElement);
    }

    styleElement.textContent = content;
  }
};

```
