Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you insert a Figure element in a contenteditable element?

I'm wondering how to implement a command to insert <figure> elements in a contenteditable element. Document.execCommand() provides an insertImage command but nothing like I'm looking for.

Here is the snippet of code I'd like to insert:

<figure>
    <img src="http://example.org/image.jpg" alt="some text" />
    <figcaption>Here is a caption</figcaption>
</figure>

Thanks

like image 893
user1415785 Avatar asked Dec 06 '25 03:12

user1415785


1 Answers

You can add your custom command and add your figure with src and caption.

See https://jsfiddle.net/2qjcLosq/

execCommand('insertfigure' ,'you_src','your_caption'); 
like image 141
m.kerkeni Avatar answered Dec 09 '25 15:12

m.kerkeni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!