Contenteditable DIV - how can I determine if the cursor is at the start or end of the content

后端 未结 5 827
一整个雨季
一整个雨季 2020-12-03 02:04

I have a contenteditable div which contains typical wysiwyg editor html (bold, anchors, lists).

I need to determine if the current cursor is, onKeyDown, at the start

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 02:12

    Simple solution for checking if cursor/caret is at the end of an input:

    this.$('input').addEventListener('keydown', (e) => {
      if (e.target.selectionEnd == e.target.value.length) {
        // DO SOMETHING
      }
    })
    

提交回复
热议问题