2

After using clone() it cloning fields with values. I need to clone duplicate fields without values.

Javascript function:

$(document).ready(function(){
   $( ".add-row" ).click(function(){
      $( "ul.sea-service" ).first().clone().appendTo( ".personal-details1" );
   });
});

Also I've tried to add .val("") in following, but also unsuccessfully:

$(document).ready(function(){
   $( ".add-row" ).click(function(){
      $( "ul.sea-service" ).first().clone().val("").appendTo( ".personal-details1" );
   });
});

Have you any ideas?

Here is JS FIDDLE, try to enter any values and press +.

3

2 Answers 2

3

Use .find('input').val('') like following.

$( ".add-row" ).click(function(){
  $( "ul.sea-service" ).first().clone().appendTo( ".personal-details1" ).find('input').val('');
});

UPDATED FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

you have to find the inputs and empty them

$( "ul.sea-service" ).first().clone().appendTo( ".personal-details1" ).find('input').val("");

https://jsfiddle.net/c68jo3kr/2/

2 Comments

This is not working... Give some input an then clone. As per your answer the value will persist.
.find('input').val('') at the end does the job

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.