BaoBao
BaoBao

Reputation: 299

Add onclick attribute to image when insertEmbed quill editor

I have inserted one image into Quill editor user this code

 const index = self._quillInstance.getSelection();
  self._quillInstance.insertEmbed(index.index, 'image', img.src);
  self._quillInstance.formatText(index.index, index.index + 1, 'height', '256px');
  self._quillInstance.formatText(index.index, index.index + 1, 'width', (256 * img.width / img.height) + 'px');
  self._quillInstance.formatText(index.index, index.index + 1, 'alt', (self._lstKeyImageBase64.length - 1).toString());
  self._quillInstance.formatText(index.index, index.index + 1, 'onclick', self.handleClickImg);

But the onclick attribute cannot insert to the img tag in editor container. How can I insert onclick event to this img was inserted to Quill?

Upvotes: 2

Views: 2056

Answers (1)

jhchen
jhchen

Reputation: 14767

formatText is meant for formatting and is not built to support inserting arbitrary HTML attributes. Also Quill needs to know about the format (by default height, width, and alt are defined for images). To add additional formats take a look at Content and Formatting

Upvotes: 1

Related Questions