-1
I have the following select:
<select id="selectChannelCam" class="custom-select">
<option value="" disabled selected>Selecione</option>
</select>
As you can see, it has only one option that is neither selectable nor selectable. I would like to add new options, but in an orderly way. Sorting is easy, but I need to insert in a specific index, because it is possible that it is necessary to insert for example channel 2 before 1.
I’ve tried to:
$('#selectChannelCam :nth-child(' + index + '))').after("<option value='" + keys[0] +"'>" + keys[0] + "</option>");
and
$("#selectChannelCam :nth-child(" + index + ")").append(new Option(keys[0], keys[0]));
The options come from where? ?
– MauroAlmeida
They depend on another register. When the user registers a channel, this channel should be added to this select. I take everything from a file
– dani
Then it aims to add options dynamically using a file for guards the options registered by the user, correct?
– MauroAlmeida
Exactly. I have already been able to put these options in an array, but to add to select (because in the file there is other information too, so I thought I’d put it in the vector)
– dani
You can sort this array before and when it is popular select will be just insert.
– MauroAlmeida