xrcwrn
xrcwrn

Reputation: 5327

Code is not working with dynamically added element

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?

Upvotes: 0

Views: 47

Answers (2)

srinath madusanka
srinath madusanka

Reputation: 592

try

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

Upvotes: 0

CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

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?

Upvotes: 1

Related Questions