0

I'm using jquery to dynamically generate textarea boxes inside of a click() event but I'd like the textareas to auto-resized but I'm having trouble getting it to fire. I'm trying to work with this example but I'm not making much progress. Here is a small sample of the area I'm having trouble with.

$(somebutton).click(function(){
    $(element).html("");
    editor=$("<textarea style=\"width:100%;\">sdf sd sds sa  sdf sad sd asd sad sad sad dasd sda s asd fasdsad</textarea>").appendTo($(element));
    $(function() {
        $(element).editor.on('input', function () {
            $(element).editor.style.height = 'auto';
            $(element).editor.style.height = ($(element).editor.scrollHeight) + 'px';
        });
    });
    $(element).editor.trigger('input');
});

Any suggestions? TY

Community
  • 1
  • 1
Vince
  • 910
  • 2
  • 13
  • 29
  • Is your `input` event triggering? – Akshay Sep 16 '16 at 10:00
  • @Akshay No it's not, but adding to my problem is that I really don't understand how $(function() { calls really work. Here is the error: "Uncaught TypeError: Cannot read property 'on' of undefined". – Vince Sep 16 '16 at 15:24
  • You can add an `id` to the `textarea` that you are appending and then do a `$("#txtarea_id").on('input', function(){});`. Or `$(editor).on('input', function () {})` – Akshay Sep 19 '16 at 14:33

0 Answers0