Remove options from select with jQuery

-1

I'm trying to get all the option's of a select that I have, but I've already used everything that is jQuery code, but they do not. I am making a filter where the person will select a city and after selecting jQuery makes a request Ajax to PHP that returns cities to make some options of a second select . This does it normally, but if the person is in the third select and change the first one for example (city) then he has to restart the other filters, resetting the option's of the second and third, and this is what I am not getting .

I'vetried:

$("#profissionalFiltro").find('option:not(:first)').remove();

$("#profissionalFiltro option").remove();

$("#profissionalFiltro").empty();

But none resolved.

    
asked by anonymous 27.07.2016 / 15:39

2 answers

2

The last line is to work. See the example

<select id="profissionalFiltro">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>
<button id="limpar">Limpar</button>

$("#limpar").click(function(event) {
    $("#profissionalFiltro").empty();
    //$("#profissionalFiltro option").remove(); //essa tambem funciona
});

Should have some other problem that is not working

link

    
27.07.2016 / 16:05
0

Just 'clean' the html of the select, as follows:

$("#profissionalFiltro").html('');

Or so:

$("#profissionalFiltro").html('<option value="">Selecione</option>');
    
27.07.2016 / 16:02