jQuery change input type=text to textarea
Solution 1:
Because a textarea
is a completely different element to input
it's easier to simply create a new textarea
and remove the input
. Try this:
$input = $("#myHiddenInput")
$textarea = $("<textarea></textarea>").attr({
id: $input.prop('id'),
name: $input.prop('name'),
value: $input.val()
});
$input.after($textarea).remove();
Solution 2:
You can always remove the element you want to change and add a new one...
Solution 3:
The problem you face is that TextArea is a an element not an attribute.
You should look to remove the previous element and replace with a new text area of the same name:
var myoldInput = $('#myInput');
var value = myoldInput.val();
$("<textarea id='myInput'></textarea>").before(myoldInput).val(value);
myoldInput.remove();