2
Hi,
I am generating fields dynamically using Jquery, and for each field I add at the end of id a counter. I wondered how I could do to remove the div that encompasses the button and the fields.
This is my form:
$contador = '';
foreach ($programas as $key => $formu){ $contador += 1;?>
<div id="campos_<?php echo $contador; ?>" name="campos[]" class="campos col-md-12" >
<input id="tbprogramacao_tv_hora_inicio_<?php echo $contador; ?>" class="form-control hora" type="text" value="<?php echo $formu->getHoraInicio(); ?>" name="tbprogramacao_tv[hora_inicio][]" maxlength="8">
<br><div class='btn btn-primary' style="border:solid 1px;" id="rmv" onclick="remover()"><span class="fa fa-minus"></span></div>
</div>
this is the function I am creating to remove:
function remover()
{
$('.campos').remove();
}
but it doesn’t work. Someone who’s been through it can help me?
When you use "." you are referring to the class. For id use "#", for tag (div, label, etc.) use only the name. In the jQuery documentation you have a list of all https://api.jquery.com/category/selectors/
– Pedro Camara Junior