0

I am trying to pass a value to a form textarea using jquery. I am able to pass a value to a hidden input area using the code below, but not able to use the same code to pass to a textarea

 <html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinymce/5.0.6/jquery.tinymce.min.js"></script>
<form>
<textarea class="tinymce" id="test"></textarea>
<button id="generate">Generate</button>
</form>

<script type="text/javascript">
    $(document).on('click','#generate',function() {

    tinyMCE.get('test').setContent('test content');
});
</script>

</html>

I tried passing values using both val and attr, but they both do not work unless the input type is hidden, I expected the textarea to show the values generated by jquery.

1 Answers1

0

$(function() {
  $('#test').val('This is a test');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea id="test"></textarea>
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
HappyAnt
  • 355
  • 1
  • 9