1
votes

Suppose i am writing sometext inside a textarea and I want to insert some text inline, inline of text, actually anywhere inline of text "NOT BEFORE" and "NOT IN LAST".

already used jquery().append() type methods.

Note i don't have any string to replace. i actually want to insert fresh text on white space inline of text right on cursor placement without affecting rest of the text formatting.

Right now i am using a jquery function and calling it using a button click and function i am using is specific for tinymce but it inserts the text in last or we can put brefore. but how to do it inline somewhere inside of text?

function insertelement(sometext){
               tinyMCE.activeEditor.setContent(tinyMCE.get('content').getContent()+sometext);
}

I hope you got the question.

1
to change text in textarea you have to replace it value with the new one. to achieve your goal just save current value of textarea in variable and add fresh text to the end and replace with current . the same about cursor position - Alex Kneller
isn't there any way to insert on white space on cursor position? - sajjad haider
i got it guys. Its simply tinyMCE.execInstanceCommand('content',"mceInsertContent",false,'text to insert'); - sajjad haider

1 Answers

1
votes

I advise you to change the editor iframe content directly.

To access the editor body you may call tinymce.activeEditor.getBody()

Now, you only need to find the postion to where you want to apply your new content and add it there (i.e. using jQuery):

var $body = $(tinymce.activeEditor.getBody());
$body.find('p:last').append($('<span>text blah blah</span>'))