Can I clone one textbox without its content??Means if I enter some values in the textbox after cloning I want an empty textbox.Is it possible?Or jquery clone returns this as an innerHtml?
By default, cloning copies the value with the <input>
currently has, but you can just clear it when cloning, for example:
var clone = $(".myInput").clone(true).val("");
Based off your comment, you'd need something like this when cloning the row:
var newRow = $(this).closest('tr').clone(true).appendTo('table')
.find('input').val('');
Just set the value of the cloned textbox to an empty string, like this:
HTML:
<input id="source" type="textbox" value="Some text..." />
<div id="target"></div>
JavaScript:
$(function() {
$("#source").clone().val("").appendTo("#target");
});
Example: http://jsfiddle.net/X5x4L/
Edit: Works with textarea aswell, see: http://jsfiddle.net/X5x4L/1/
In my case, I had a lot of fields in the form, so to make all them null after clonning:
$('.user-address:first').clone().appendTo('.user-addresses');
$('.user-address:last').find('[name]').val(null);
Hole helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With