Skip to content
Advertisement

how to manipulate image before display in contenteditable element?

I need to manipulate img element before inserting it into a contenteditable div.

here next is my attempt. to do ..

  1. add EditorImgs class to the image assign
  2. add src to that image

JavaScript
JavaScript
JavaScript

Advertisement

Answer

When using document.execCommand('insertImage'), the third argument should be the URL, not an image element.

JavaScript

If you want to style the image, you could use document.execCommand('insertHTML') or Range#insertNode.

JavaScript

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement