clone inputs but with empty values with Jquery
I have this bulk of HTML:
<div class="bundle" id="bun">
<div>
<label for="title">title:</label><input name="name" id="name" value="led zeppelin III" type="text">
</div>
<div>
<label for="content">content:</label><textarea type="textarea" cols="100" rows="3" name="content" id="content">composed largely at a remote cottage in wales known as Bron-Yr-Aur, this work represented a maturing of the band's music towards a greater emphasis on folk and acoustic sounds. this surprised many fans and critics, and upon its release the album received rather indifferent reviews</textarea>
</div>
<div>
<label for="url">url for image:</label><input name="url" id="url" value="http://www.bob.co.il/wp-开发者_如何学运维content/themes/CMOTA-1.0/demo-images/3.jpg" type="text">
</div>
<img src="http://www.bob.co.il/wp-content/themes/CMOTA-1.0/demo-images/3.jpg" alt="led zeppelin III" height="272">
</div>
and i'm using the clone() jquery method to copy this bulk for to the end of the form:
var newElem = $('#bun' + val).clone().attr('id', 'bun' + newval);
newElem.children('input:first').attr('name', 'title' + newval).attr('id', 'title' + newval);
newElem.children('textarea:first').attr('name', 'content' + newval).attr('id', 'content' + newval);
newElem.children('input:nth-child(2)').attr('name', 'url' + newval).attr('id', 'url' + newval);
$('#bun' + val).after(newElem);
it does work but i want to clone only the content of the "bun" element without the value of the inputs and the src of the image. how should i approach this?
thanks.
var newElem = $('#bun' + val).clone().attr('id', 'bun' + newval);
newElem.children('input:first').attr('name', 'title' + newval).attr('id', 'title' + newval);
newElem.children('textarea:first').attr('name', 'content' + newval).attr('id', 'content' + newval);
newElem.children('input:nth-child(2)').attr('name', 'url' + newval).attr('id', 'url' + newval);
$('#bun' + val).after(newElem);
newElem.find('input,textarea').val('');
精彩评论