I happen to have the following situation, in my HTML I own the structure this way:
<div class="form-row mt-3">
<select name="produto0" class="form-control{{ $errors->has('produtos') ? ' is-invalid' : '' }}">
@foreach($produtos as $p)
<option value="{{$p->id}}">{{$p->nome}}</option>
@endforeach
</select>
</div>
<a href="javascript:void(0)" class="btn btn-sm text-white bg-info" id="adicionar">
<i class="fa fa-plus-square"></i> ADICIONAR NOVO PRODUTO</span>
</a>
And then when I click on the button that has the id="adicionar"
code in jQuery clone and repeat that snippet below, follow the code in jQuery :
$( "#adicionar" ).click(function(e) {
e.preventDefault();
var original = $(this).closest(".form-row");
var copia = original.clone(true, true);
original.after(copia);
});
After that I would like the next clone code, that is equal, to have the name="produto0"
attribute, for example name="produto1"
, how to do this using jQuery p>