views:

323

answers:

2

i use jquery elastic plugin for expanding a textbox. it works great but i want to use this on a textbox that is added to the DOM with ajax but unfortunately this plugin has no live built-in function.

is there a way to solve this?

http://www.unwrongest.com/projects/elastic/

+2  A: 

With jQuery 1.4, you can do this:

$("textarea").live("focus", function() {
    $(this).elastic().die("focus");
});

jQuery 1.3.x does not support the focus event for live(), so it gets a little trickier:

$("textarea").live("keydown", elasticize).live("mousedown", elasticize);

function elasticize() {
    $(this).elastic().die("keydown").die("mousedown");
}

The die calls are there so elastic is only called once for each textarea.

jimyi
but why would anyone use 1.3 when 1.4 is out there?=)
weng
hm i noticed that ive got 1.3 and 1.4 isnt downloadable on their site..where can u get it?
weng
1.4 is still in alpha - http://blog.jquery.com/2009/12/18/jquery-14-alpha-2-released/
jimyi
+2  A: 

If you have control over the textarea creation, then simply call .elastic() on the textarea once it is created:

// In whatever AJAX callback creates the textarea...
var newTextarea = $('<textarea></textarea>');

// Append the element to the DOM wherever it belongs...
parentElement.append(newTextarea);

// Add elastic behavior.
newTextarea.elastic();
Annabelle