copy/duplicate live data from div to textarea using jquery

I have create a rich text editor using DIV as editor container. How can I pass the DIV value to textarea? I already use jquery code. it success when I view it live but when I submit the form, the textarea value is empty. Here is my code:-

HTML

Read More
<div id="rte" contenteditable="true" unselectable="off">
</div>
<textarea name='rteHide' id='stage'></textarea>

JQuery

$(function() {
$("#rte").keyup(function() {
    var content = $('#rte').html();
    $("#stage").text(content);
});
});

I’m using this for wordpress plugin. Please let me know if there any other way to pass DIV value without using .post() jquery. Or using textarea as rich text editor container.

I required to create this editor instead using the current existing rich editor because we want to do enhancement in future.

Thanks in advance.

Related posts

Leave a Reply

1 comment

  1. Try to use val() instead of text() to set the value of your textarea

    $("#stage").val(content);
    

    Also, to make sure that there’s no conflict happen here, you can wrap your code inside:

    jQuery(document).ready(function($) {
        $("#rte").keyup(function() {
            var content = $('#rte').html();
            $("#stage").val(content);
        });
    });