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?
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?
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.
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();