Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write or delete string in textarea using jodit editor

I am using Jodit as text editor and I would like to delete a text within a textarea using jquery/javascript, but it seems I can not do it. I can read the textarea with $('#xxx').val(); but cannot write using e.g. $('#xxx').val('yyy');

I am adding some code hoping it will be more clear:

<form>
    <textarea id="test">Hi</textarea>
</form>

<script>
    $('textarea').each(function () {
        var editor = new Jodit(this);
    });

    $('#test').val('Bye');
</script>

But the string in the textarea does not change. Also if try to delete it:

<script>
    $('#test').val('');
</script>

Nothing happens.

like image 489
Floriano Avatar asked Feb 11 '26 20:02

Floriano


1 Answers

You need to perform operation on editor object not directly on textarea.following example update text for jodit.

var editor = new Jodit('#editor');
editor.value = '<p>start</p>';

You can use this editor.value property to change text.

For your scenario below code will work

<form>
    <textarea id="test">Hi</textarea>
</form>

<script>
    var editor = = new Jodit('#test');    
    editor.value = 'any value here';
</script>
like image 165
Jigar Avatar answered Feb 13 '26 08:02

Jigar