javascripttinymce

tinyMCE get the current selected HTML element


I've an editor in which I can select text and display it by the following code :

alert(tinyMCE.activeEditor.selection.getContent({format : "html"}));

the issue is the function returns only text and not HtmlElement. So I can't see, for example, the node which encapsulate this selected text. I would like to get the content but by an HtmlElement to deal with nodes.

Any suggestions ?


Solution

  • Take a look at getNode():

    tinymce.activeEditor.selection.getNode();
    

    The API calls available on a selection are documented here: https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.dom.selection/#getNode