Front/JS & jQuery

[js] quill editor focus()

오선지♬ 2024. 2. 11. 10:28
728x90
반응형
// Initialize Quill
    var quill = new Quill('#quill-container', {
      theme: 'snow' // or 'bubble'
    });

    // Function to set focus at the end of the document
    function focusAtEnd() {
      var length = quill.getLength();
      quill.setSelection(length, length);
      quill.focus();
    }

    // Example: Set focus to the end when a button is clicked
    document.getElementById('your-button-id').addEventListener('click', function() {
      focusAtEnd();
    });

- 커서 활성화 : .focus()

- 맨뒤에 커서 활성화하기위해서 quill.getLength() 로 길이를 구해서 .setSelection()으로 원하는 위치에 커서를 이동시킬 수   있다.

728x90
반응형