B
B
BushaevDenis2018-02-25 07:35:52
JavaScript
BushaevDenis, 2018-02-25 07:35:52

How to clear all input value in clone?

For example, I clone a div that has several inputs.
Everything is cloned correctly, except that the "val()" values ​​of the inputs are also cloned.
How can this be avoided?
Let's say

<div>
<input name="name">
</div>

And if you write, for example, "Petya", then js will copy this div along with the value of the input. And in the end it will
$('div').eq(0).clone.appentTo('body');
$('div').eq(0).find('input').eq(0).val(); // Петя
$('div').eq(1).find('input').eq(0).val(); // Петя

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kreotech, 2018-02-25
@BushaevDenis

Can you do it like this

$('div').eq(0).clone().find('input').val('').end().appendTo('body');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question