0

As I know, the Evernote editor is the Rich Text Editor and differences between the input or textarea tag, so I can not use the following code to judge the type of it, is there a method to get the current element of Evernote editor where the cursor is by JavaScript instead of jQuery?

e.target.localName.toLowerCase() === 'input' || e.target.localName.toLowerCase() === 'textarea'
lyscop
  • 77
  • 1
  • 8

1 Answers1

0

Evernote Editor is one of WYSIWYG HTML Editor

You can use WYSIWYG editor with attribute contentEditable="true" on html tag

For get current element on cursor, you can find answer on Get element node at caret position (in contentEditable)

Or I have some simple code that I use on my project

getCaretNode() {
   let selection: any;
   if (window.getSelection) {
     selection = window.getSelection();
   } else if (document.getSelection() && document.getSelection().type !== "Control") {
     selection = document.getSelection();
   }
   let anchorNode = selection.anchorNode;
   if (anchorNode === null) {
     return null;
   }
   if (anchorNode.nodeType === 3) {
     anchorNode = anchorNode.parentNode;
   }
   return anchorNode;
}
Do Trung Duc
  • 396
  • 3
  • 13