A few things you should probably do differently.
$("#test").dblclick( function() { $(this).wrapInner("<textarea/>").find('textarea').focus(); }).delegate('textarea','blur',function() { $(this).parent().text( this.value ); });
- Bind
dblclick directly to #test - In the
dblclick .find() handler, the new textarea and .focus() on it - Put the
.delegate() handler on #test instead of .live() - Use
blur instead of mouseleave - In the
blur handler, set .text() of #test to value textarea . (This is important in order to pick up the changes made.)
Example: http://jsfiddle.net/drQkp/1/
Example: http://jsfiddle.net/drQkp/2/
Here is an example that allows you to enter HTML in a text box.
$("#test").dblclick(function() { $(this).html($("<textarea/>",{html:this.innerHTML})).find('textarea').focus(); }).delegate('textarea', 'blur', function() { $(this).parent().html(this.value); });
user113716
source share