简体   繁体   English

如何删除以前克隆的div的添加按钮?

[英]how to remove add button for previous cloned div?

actually I am cloning div using clone method when I clone it is appending entire along with add and remove buttons but I need show when I click on add button it should clone entire div with add and remove button but it should not show add button for previous cloned div . 实际上我克隆div克隆方法,当我克隆它是追加整个以及添加和删除按钮但我需要显示当我点击添加按钮它应该克隆整个div添加和删除按钮但它不应该显示添加按钮为以前克隆的div

How to solve this?? 怎么解决这个? somebody help me.. 来人帮帮我..

Below is HTML code.. 以下是HTML代码..

<div class="wid100 cf1">
    <div class="group1 nopl"><label>Company :</label> <input type="text" class="company_name" name="company[]" required="required" /></div>
    <div class="group1 nopl"><label>Experience (Yrs) From:</label> <input type="date" class="experience_1" id="filevalidation" name="experience1[]" required="required" /></div>
    <div class="group1 nopl"><label>To:</label> <input type="date" id="filevalidation"  class="experience_2" name="experience2[]" required="required" /></div>
    <label>Roles & Responsibilities :</label> <textarea rows="6" class="job" name="job_description[]" required="required" ></textarea>
    <div class="add2">+</div><div class="remove2">-</div>
</div>

Jquery code, Jquery代码,

 $(document).ready(function() {
 $('.remove2').hide();

 var count = 1;
  $(".add2").click(function() {

  if(count<5){
    count++;

    $(".cf1:first").clone(true).insertAfter(".cf1:last");
    $(".cf1:last").find('input[type="text"]').val('');
    $(".cf1:last").find('input[type="date"]').val('');
    $(".cf1:last").find("textarea[name=job_description]").val('');
    $(".add2:last").closest(".add2").remove();
    $(".remove2:last").show('');
   }
   else{
    $(this).closest(".add2").remove();    
     count--;
   } 
});

$(".remove2").click(function() {
    if(count>1){
    $('.cf1:last').remove();
     count--;
    }
});
});

I update fiddle here now add button is not adding 我更新小提琴这里现在添加按钮不加入

$(".cf1:last .add2").hide(); 

inside your click event 在你的点击事件中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM