Couim
Couim

Reputation: 747

tinymce select html node with mouse

I've a tinyMCE editor and I would like to get in javascript the entire node of a selected word (by mouse). I can get that just by clicking on the tag at the end of the editor like that :

tinyMCE demo

So when I click on the span button I can see my text is selected and when I run this javascipt line I get what I want :

console.log("output : " + tinymce.activeEditor.selection.getContent({format : 'html'}));

Result :

output : <span style="color: #00ff00;">EAM</span>

But when I run the same javascript line after selected the text with my mouse pointer I just get the following result :

EAM

Do you know how can I get the HTML format when selecting text by mouse ? Thanks

Upvotes: 1

Views: 537

Answers (1)

Roman Miroshnychenko
Roman Miroshnychenko

Reputation: 1564

Maybe editor.selection.getNode()?

https://www.tinymce.com/docs/api/tinymce.dom/tinymce.dom.selection/#getnode

Or if you need html as a string:

let node = editor.selection.getNode();
let tmp = document.createElement("div");
tmp.appendChild(node);
let html = tmp.innerHTML;

Upvotes: 1

Related Questions