I am passing data to the Bootstrap modal using jQuery from my database. The form values can change from a single row to multiple rows. I do not want a scrollbar, but instead I want the textarea element to automatically adjust its height to fit the content. How can I achieve this? Below is my HTML code,
<div class="modal-body">
<div class="form-group">
<label class="col-form-label">Background:</label>
<textarea class="form-control bg" disabled> </textarea>
I am using the following jQuery to populate the text area with value,
$('#Modal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var back = button.data('back')
var modal = $(this)
modal.find($('.bg')).val(back);
Currently, the text area displays a vertical scrollbar which I am trying to avoid. Instead, I want the text area to dynamically adjust its height based on the content.
I need to stick to using only the "Textarea" element as it preserves the content formatting. I attempted to retrieve the scrollheight of the bg class but it returned zero. It seems like it's not capturing the textarea value after executing the above jQuery script.
I have spent over 5 hours working on this without finding a solution. Your assistance would be greatly appreciated.