trix - insert text - issue
by radek
HTML
<link rel="stylesheet" type="text/css" href="https://unpkg.com/trix@2.1.3/dist/trix.css">
<!-- <script type="text/javascript" src="https://unpkg.com/trix@2.1.3/dist/trix.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.0/trix.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.0/trix.js"></script>
<input id="x" value="Editor content goes here" type="hidden" name="content">
<trix-editor input="x"></trix-editor>
JavaScript
/* what the newly created button does */
// document.addEventListener("load", function(event) {
document.addEventListener("DOMContentLoaded", function(event) {
// Your code to run since DOM is loaded and ready
var element2 = document.querySelector("trix-editor")
element2.editor // is a Trix.Editor instance
element2.editor.insertString("Hello2")
});
//var element = document.querySelector("trix-editor")
//element.editor // is a Trix.Editor instance
//const editor = document.querySelector('trix-editor').editor
//const length = element.editor.getDocument().toString().length
//console.log(length)
//element.editor.setSelectedRange(length - 1)
// Insert “Hello” at the beginning of the document
//element.editor.setSelectedRange([0, 0])
//element.editor.insertString("Hello")