This also works correctly with the value attribute:
$('input').each(function() { var attrs = {}; $.each(this.attributes, function() { attrs[this.name] = this.value; }); $(this).replaceWith($('<textarea>').prop(attrs)); });
Example: http://jsfiddle.net/FyYDT/
ADDED
If you want jQuery events to go through (not recommended), you need to relink them. Sort of:
$('input').click(function() { alert('hey'); }).each(function() { var attrs = {}, ta = $('<textarea>'); $.each(this.attributes, function() { attrs[this.name] = this.value; }); $.each($(this).data('events'), function(i, f) { $.each(f, function(){ ta.bind(i, this.handler); }); }); $(this).replaceWith(ta.prop(attrs)); });
http://jsfiddle.net/FyYDT/1/
David source share