0

I was adding and removing controls dynamically. However, I have a small requirement.

Below one is Jsbin code. https://jsbin.com/tuxacitoju/1/edit?html,output

  1. Open the link.
  2. Click “Adperson”
  3. Now click Remove two times.

Observe, all control are removed and then you are not allowed to add controls.

My page should have at least one set of controls.

Thanks, Balu

0

2 Answers 2

1

Just add and if statement to check if there are more than one rows before deleting. For example:

$("#associationRemove").on("click", function(){
  if ($(".cloneMe").length > 1) $(".cloneMe:last").remove();
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can simply do:

  $("#associationRemove").on("click", function(){
      if($(".cloneMe").length > 1){
        $(".cloneMe:last").remove();  
      }
  });

Comments

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.