KutePHP
KutePHP

Reputation: 2236

how to get id of a node in TinyMCE?

I want to get the id of a node inside TinyMCE.

I searched in the documentation, but could not find this.

How can this be done?

Upvotes: 6

Views: 5185

Answers (2)

BJ Patel
BJ Patel

Reputation: 6278

let say if you have id as txtatinyID

 <textarea class="editorHtml" id="txtatinyID"></textarea>

so following will return txtatinyID in tinyMCE V4

$(tinymce.activeEditor.selection.getNode()).closest('body').data('id')

So it will find the body of the current active editor and on the base of it will look for body and in it will get the value of data-id.

Upvotes: 0

Thariama
Thariama

Reputation: 50840

First, it is important which node you want to get the id from. If you want to get the if of the parent node of your selection in TinyMCE use

tinymce.activeEditor.selection.getNode().id;

EDIT: In case you have a single node in your editor you can access this node id using

tinymce.activeEditor.getBody().firstChild.id;

Upvotes: 7

Related Questions