最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - write or delete string in textarea using jodit editor - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Jan 22, 2019 at 4:42 Floriano asked Jan 22, 2019 at 4:14 FlorianoFloriano 932 silver badges6 bronze badges 3
  • Can you provide an example of the code which is not working (html, js)? The code you provided works for me – Nick Parsons Commented Jan 22, 2019 at 4:17
  • Please provide plete code of what you've tried.As it is unclear what you're asking. – Black Mamba Commented Jan 22, 2019 at 4:20
  • Please provide code, such that i can help you – Xavier Issac Commented Jan 22, 2019 at 4:22
Add a ment  | 

4 Answers 4

Reset to default 5

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>

It may be better to use the Jodit provided function to set the value of the editor instead of doing it directly on the attribute. Using an interface like this will allow for forward patibility if Jodit ever changes the editor.value.

In the same spot you instantiate the editor:

var editor = new Jodit(this)
editor.setEditorValue('some value')

The code you have should work perfectly:

function change() {
  $("#text").val("Changed words");
}
<script src="https://code.jquery./jquery-3.3.1.js"></script>

<textarea id="text">Example words</textarea>

<button onclick="change()">Change text</button>

Here's the official documentation example hope it is what you're searching for:

$('textarea').each(function () {
    var editor = new Jodit(this);
    console.log(editor.value);
});

The doc

发布评论

评论列表(0)

  1. 暂无评论