Resize text area to fit all text on load jquery

后端 未结 7 950
走了就别回头了
走了就别回头了 2020-12-08 06:19

I understand there has been a lot of discussion on this but I have yet to find a solution to fix my needs. Basically I need to autogrow a text area not when you type but on

相关标签:
7条回答
  • 2020-12-08 06:53

    The solution of Tormod Haugene worked for me.

    But my textareas where in an accordion and apparently it only worked if the textarea was visible on page load. The accordion items are triggered by clicking on elements with the class "title".

    So I adapted the code Tormod Haugene to work inside accordion contents, that are set to display: none on page load.

    Maybe this is useful for someone else in this situation:

    jQuery(document).on('click', '.title', function () {
        jQuery("textarea").each(function () {
            this.style.height = (this.scrollHeight+10)+'px';
        });
    });
    
    0 讨论(0)
提交回复
热议问题