I have a text input that I’d like to replace with a textarea, preserving all of the attributes. How can I do this with jQuery?
Sample input:
<input type="text" name="newfeature" id="newfeature"
class="form-required" tabindex="3"
aria-required="true" />
Desired output:
<textarea type="text" name="newfeature" id="newfeature"
class="form-required" tabindex="3"
aria-required="true"></textarea>
I know this can be done manually using the .prop() selector and specifying each attribute/property, but how can I do it dynamically?
Also, this is not necessary, but would it possible to preserve the bindings when doing this?
This also works with the
valueattribute correctly:Example: http://jsfiddle.net/FyYDT/
ADDED
If you want jQuery events to pass along (not recommended), you need to re-bind them. Something like:
http://jsfiddle.net/FyYDT/1/