How can I add or Remove an Option in a Selector, I have a selector like this:
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
I want an Add Button and a Remove Button added to it.
The Add button can add a new Option and the Remove if I select an Option I can push remove to delete it automatically
$('select[name=things]').change(function() {
if ($(this).val() == '') {
var newThing = prompt('Enter a name for the new thing:');
var newValue = $('option', this).length;
$('<option>')
.text(newThing)
.attr('value', newValue)
.insertBefore($('option[value=]', this));
$(this).val(newValue);
}
});
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<select name="things">
<option value="1">Thing One</option>
<option value="2">Thing Two</option>
<option value="3">Thing Three</option>
<option value="">New Thing…</option>
</select>
This Could work for Me but I want the New Thing on a + Button and a Remove button added to it.
What do you guys think?