Add_Remove_button_jquery

 <body>

    <div id="block">
    <input type=text name='text' id='text' >
<!-- <button id="btnRemove">Remove</button> -->
    <!-- <input type="text" name="text1" id="text1"> -->
</div>
    <button id='bt'>Add</button>
    <script>
        $(document).ready(function(){
            count=0;
            $("#bt").click(function(){
                id=$('input').first().attr('id');
                //alert(id);
                //console.log(id);
count=count+1;
alert(count);
                id=id+""+count;
                $("#block").append(`<div class='con'><input type='text' id=${id}><input type="button" id="btnRemove" value="Remove"/></con>`);
             
            });
      
            $('body').on('click','#btnRemove',function() {
    //alert("remove button clicked");

    $(this).parent('div.con').remove();
  });
    
});
        </script>

Comments

Popular posts from this blog

interview questions js[ Anurag Singh ProCodrr]

reactnative_creation