Hello,
My question is that I want to get the html code for the string that the user has written in the text area.
For example:
This is an <b>example</b>
But I get this:
"text":[{"text":[{"type":"string","attributes":{"bold":true},"string":"Rgg v"},{"type":"string","attributes":{"blockBreak":true},"string":"\n"}],"attributes":[]}]
My code is (the var doc returns me the code above):
<script type="text/javascript">
document.addEventListener('trix-change', function(e){
var element = document.querySelector("trix-editor");
var doc = element.editor.getDocument();
});
</script>
You can get the HTML from the <trix-editor>'s value property:
document.querySelector("trix-editor").value // "<div>This is an <strong>example</strong></div>"
In a Trix event handler:
document.addEventListener("trix-change", function(event) {
var element = event.target
var html = element.value // "<div>This is an <strong>example</strong></div>"
})
Most helpful comment
You can get the HTML from the
<trix-editor>'svalueproperty:In a Trix event handler: