0

I am using following code

$(document).ready(function() {
    $(".text_message").autosize();
}

for autosizing the text box. My problem is this is not working for dynamically added text boxes. How to resolve this?

3
  • 1
    autosize.update seems to be the way to do it looking at the docs Commented Feb 27, 2015 at 11:02
  • Can you show the code how are you adding that .text_message to the DOM? You can do it after adding the new object, but I can't answer without seeing the code. Commented Feb 27, 2015 at 11:04
  • You need to initialize the plugin for those dynamic elements after they are created Commented Feb 27, 2015 at 11:04

2 Answers 2

1

Because the script runs on $(document).ready it will only work for elements that exist when your page loads.

You need to use something like the on method on the parent so that elements added after are also affected.

http://api.jquery.com/on/

Another good reference: Event binding on dynamically created elements?

Sign up to request clarification or add additional context in comments.

Comments

0

try

$( document ).ajaxComplete(function() {
   $(".text_message").autosize();
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.