SCEditor

insert()

insert(value) Since: 1.3.5

Inserts text into the editor at the position of the cursor.

If end is not null and there is some selected text, the selected text will be placed between the start and end strings.

If there is no selection and end is set, it will just be appended to the end of start before inserting.

Syntax

instance.insert(start[, end][, filter][, convertEmoticons][, mixedValue]);

Parameters

start
Type: String

The value to insert

filter
Type: Boolean
Default: true

If to filter the value through any plugins. For example if using the BBCode format, should this filter

convertEmoticons
Type: Boolean
Default: true

If to convert emoticons codes (:)) into emoticons.

mixedValue
Type: Boolean
Default: false
Since: 1.4.3

If to allow both HTML and filtered content (BBCode if using the BBCode format) at the same time. If filter is not set to true this option will have no effect.

Return

Type: sceditor

Example

Inserting HTML:

var textarea = ...;
var instance = sceditor.instance(textarea);

instance.insert('Hello World!');

If using the BBCode format, BBCode should be passed instead of HTML:

var textarea = ...;
var instance = sceditor.instance(textarea);

instance.insert('Hello [b]World![/b]');

If filter is set to false, HTML can be passed even when using the BBCode format:

var textarea = ...;
var instance = sceditor.instance(textarea);

instance.insert('Hello World!', false);

The mixedValue allows both HTML and filtered text (BBCode if using the BBCode format) to be inserted at the same time:

var textarea = ...;
var instance = sceditor.instance(textarea);

instance.insert(
    '[b]BBCode[/b] and HTML!',
    true, // filter
    true, // convert emoticons
    true  // allow mixed
);