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?

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
xrcwrn
  • 5,339
  • 17
  • 68
  • 129
  • 1
    `autosize.update` seems to be the way to do it looking at the docs – atmd Feb 27 '15 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. – Zoran P. Feb 27 '15 at 11:04
  • You need to initialize the plugin for those dynamic elements after they are created – Arun P Johny Feb 27 '15 at 11:04

2 Answers2

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?

Community
  • 1
  • 1
CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
0

try

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