Remove hidden jQuery field

0

I have the following form:

<button type="button" id="remover<? echo $valor->int_cod; ?>" idProspect="<? echo $valor->int_cod; ?>" value="<? echo $valor->int_cod; ?>" class="btn btn-primary btn-xs pequeno remover"><? echo $valor->int_nome." - ".$valor->int_whatsapp; ?></button>

<input type="hidden" class="hide" idprospect="<? echo $valor->int_cod; ?>" value="<? echo $valor->int_cod; ?>" name="prospects[]">

I would like to click on it, remove it. I did the following way:

$(".remover").click(function(){
    var idProspect = $(this).attr("idProspect");
    $("#remover"+idProspect).remove();
});

However, only removed the button, hidden does not remove. How do I remove hidden?

    
asked by anonymous 12.10.2016 / 23:24

3 answers

1

Note that when you run $("#remover"+idProspect).remove(); , remove() refers only to $("#remover"+idProspect) , then you would also need to do so for the input by adding $("input[type=hidden]").remove(); , $(".remove").remove(); , $(this).next().remove(); or form which is more convenient for your situation.

In case $(".remove").remove(); removes all elements with class remove , $("input[type=hidden]").remove(); removes all input of type hidden , $(this).next().remove(); removes only the next element to the clicked button.

    
13.10.2016 / 00:06
1

The example below excludes as you wish but would have to use "Class" to refer to more than one element:

<input type="text" class="remover" value="value1">
<input type="text" class="remover" value="value2">
<input type="hidden" class="remover" value="value3">
<a id="removerTodos" href="#">Remover</a>
<a id="contarInput" href="#">Contar input ativos</a>


$('#removerTodos').click(function(e){
   $('.remover').remove();
});

$('#contarInput').click(function(e){
   var qtd = $('input').size();
   alert(qtd);
});
    
13.10.2016 / 00:01
1

Here is a simpler way to do this. If you do not want to, add the value $ value-> int_cod in the class and not in the element id, because by adding the value $ value-> int_cod in the element id, you will be creating two identical IDs.

<button class="remove">Botão</button>
<input type="hidden" class="remove"/>

$(document).ready(function() {
    $('.remove').on('click', function() {
        $('.remove').remove();
    });
});
    
13.10.2016 / 00:03