Spiral
2 months ago
407
4
Laravel

How to put a condition on two different id in jquery for append

Posted 2 months ago by Spiral

Hi! I want to put a condition on two ids when click on one id then will not another create

This is my code plz give me the best solution

<script type="text/javascript">
   		$(document).ready(function(){

   			var i = 0;
		       
		    $("#add").click(function(){
		   
		        ++i;	   

		        if ($('#params')) {
		        	alert('params');
		        	$('#params').append('<div class="parent-div"><div class="row"><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="params[0][key]" class="form-control" placeholder="Key"></div></div><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="params[0][value]" class="form-control" placeholder="Value"></div></div><a  id="remove" name="remove" class="action-icon  fa fa-minus-circle" style="margin-top: 10px;"></a></div></div></div>')
		        }	

		        alert('header');
		        $('$header').append('<div class="parent-div"><div class="row"><div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="header[0][key]" class="form-control" placeholder="Key"></div></div><div class="col-xs-4 col-sm-4 col-md-4 col-lg-4"><div class="form-group"><input type="text" name="header[0][value]" class="form-control" placeholder="Value"></div></div><a  id="remove" name="remove" class="action-icon  fa fa-minus-circle" style="margin-top: 10px;"></a></div></div></div>');

		    });
		   
		   	$(document).on('click', '#remove', function(){  
		         $('.parent-div').remove();
		    });	    	
		});	  	   
	</script>

Please sign in or create an account to participate in this conversation.