I am using the quill text editor in a javascript app and I need to retrieve the contents of the text editor as a string with the HTML included but the docs are a little sparse on this subject.
-
You might be interested in seeing [this](https://github.com/loagit/Quill-Examples-and-FAQ) too. – Loa Dec 30 '19 at 16:18
5 Answers
Depends what you want to get, here's an example showing a few ways:
http://codepen.io/k3no/pen/amwpqk
var delta = editor.getContents();
var text = editor.getText();
var justHtml = editor.root.innerHTML;
preciousContent.innerHTML = JSON.stringify(delta);
justTextContent.innerHTML = text;
justHtmlContent.innerHTML = justHtml;

- 3,694
- 2
- 21
- 40
-
-
2Hi, @AnjanaSilva. I'm just here to point out a very useful [Quill repository](https://github.com/loagit/Quill-Examples-and-FAQ). – Loa Dec 30 '19 at 16:16
-
Is it possible to get the returned `justHtml` to respect the new lines? I always seem to get everything back in one line. – Digital Ninja Jan 20 '20 at 02:16
-
But how to put it in a simple Input field in the HTML FORM? Thanks! – Gediminas Šukys Feb 12 '20 at 14:19
Quite simply by accessing the editor's innerHTML:
var quill = new Quill('#editor', {
theme: 'snow'
});
// ....
var editor_content = quill.container.innerHTML // or quill.container.firstChild.innerHTML could also work
Hope this helps!

- 3,072
- 2
- 15
- 17
-
23.container.innerHTML will get both the editor HTML and the content HTML. To get only the content HTML without the editor I use root.innerHTML – Bagus Aji Santoso Feb 19 '18 at 04:08
This was great for getting the text from the editor and answers OP's question, but the text still wasn't showing up in the posted form. Others may come here with the same problem, so I'm posting the solution to that here.
I had to manually add the text from the editor to the form's dom.
document.getElementById('formSave').addEventListener('submit', validate);
function validate(e) {
let blogHtml = editor.root.innerHTML;
// do validations and do e.preventDefault() on fail, but if valid, then...
let input = document.createElement('input');
input.setAttribute('name', 'blog');
input.setAttribute('value', blogHtml);
input.setAttribute('type', 'text')
document.getElementById('formSave').appendChild(input);
}

- 361
- 2
- 6
if you want just what you written inside root.innerHTML
is better option because .container.innerHTML
give you bunch of other tags that is inside the .editor
class.
const myEditor = new Quill('#my-editor', {
//configuration
});
myEditor.root.innerHTML;
add if you want to get the text after change use on
event
myEditor.on('text-change', function(delta, oldDelta, source) {
//on change opration
});

- 1,375
- 2
- 6
- 21
This is so easy process, let me guide you.
initialize and config:
var quill = new Quill('#editor-container', {
modules: {
syntax: true,
toolbar: '#toolbar-container'
},
placeholder: 'Compose an epic...',
theme: 'snow',
readOnly: false,
});
Now get content on changing the editor data
quill.on('text-change', function(delta, source) {
var justHtml = quill.root.innerHTML;
document.getElementById('output-html').innerHTML = justHtml;
});
HTML code:
<div class="ql-snow">
<div class="ql-editor" id="output-html">
// the content goes here
</div>
</div>

- 576
- 6
- 18