sharepoint designer – How to find the right ID to reference a rich text editor field in order to manipulate it?

Sharepoint 2016 on site:

My ultimate goal is to be able to insert tags into a rich text field for use in email templates. And I must be able to drop the tags at the exact location of the cursor.

I can make it work in the basic text fields by accessing the field via the id: document.getElementById (fieldID).

But when I try the same thing with a field rte, I can not find the correct identifier that will allow me to fill in the field if necessary.

I have found some possible identifiers for the field but none of them works. They return an undefined or null object. This identifier (Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_spSave) let me access the item but it's the hidden version so I can not handle it.

I've also tried all jQuery call combinations and I am able to read the text in the field, but I can not get descriptor on the right object that allows me to insert text at the cursor location.

The name of the field is & # 39; Body & # 39; The label is & quot; Body of Email & quot ;.

Any ideas on how can I get a handle on the rte object to be able to insert tags?

Thank you!

Full code below:

                AddTags function (field name) {
// GOAL: Insert {tags} in the cursor position of the desired field
// field name: subject or body

if (field name == "Subject") {

// standard text field
var fieldID = "Subject_a4231a67-4c6e-4c42-8069-259dfa5934c4_ $ TextField";
var txtarea = document.getElementById (fieldID);

} other {

// field name = & # 39; Body & # 39;
// Rich Text Editor field

// possible IDs:
// Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_topDiv
// Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_inplacerte
// Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_topDiv
// Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_spSave
// Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_inplacerte_label

// var txtarea = document.getElementById (Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_topDiv & # 39;); // return an undefined DIV element
// var txtarea = document.getElementById (-Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_spSave & # 39;); // find the item but it is hidden, so impossible to use
// var txtarea = document.getElementById (-Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_inplacerte & # 39;); // return an undefined DIV element

var txtarea = document.getElementById (Body_2a4c2989-39fe-44db-a783-3559dc47ddea_ $ TextField_spSave & # 39;); // find the item but it is hidden, so impossible to use
// - >> Can not set property & # 39; selectionEnd & # 39; on & # 39; HTMLInputElement: The type of entry element (& # 39; hidden & # 39;) & # 39;) does not support selection.

// var txtarea = $ (& textarea[id="Body_2a4c2989-39fe-44db-a783-3559dc47ddea_$TextField_spSave"]& # 39;); // undefined
// var txtarea = $ (& textarea[id="Body_2a4c2989-39fe-44db-a783-3559dc47ddea_$TextField_topDiv"]& # 39;); // undefined
// var txtarea = $ (& textarea[id="Body_2a4c2989-39fe-44db-a783-3559dc47ddea_$TextField_inplacerte"]& # 39;); // undefined

// var txtarea = document.getElementById ('Body'); // return null

// WORKS TO GET TEXT ON THE FIELD
// var comments = $ (& # 39; nobr: contains ("Body of Email") & # 39;). the closest ("tr"). find ("div.ms-rtestate-write"). html ();
// alert (comments);
//  return;

// ... BUT THAT DOES NOT GIVE ME THE NECESSARY PURPOSE
// var txtarea = $ (# nobr: contains ("Body of e-mail") & # 39;). the closest ("tr"). find ("div.ms-rtestate-write"); //no

};

// This part was found on another site and inserts [b] tags but that's close to what I need.
var start = txtarea.selectionStart;
var end = txtarea.selectionEnd;
var sel = txtarea.value.substring (start, end);
var finText = txtarea.value.substring (0, start) + & # 39;[b]& # 39; + salt + & # 39;[/b]& # 39; + txtarea.value.substring (end);
txtarea.value = finText;
txtarea.focus ();
txtarea.selectionEnd = end + 7;

};