Hola, cómo eliminar el valor vacío en la selección múltiple, debajo de mi código
$(document).on('blur','.select2-search__field', function(e) { var current_select = window.localStorage.getItem("current_select"); console.log($(this).val()); if (current_select) { if ($(this).val()) { $("#"+current_select).append('<option value="'+$(this).val()+'" selected>'+$(this).val()+'</option>'); //$("#"+current_select).val($(this).val()); $("#"+current_select).trigger("change"); } } });cuando ingreso nuevos valores, ese valor agregado funciona, pero al mismo tiempo aparece automáticamente un valor vacío, así que, ¿cómo puedo eliminarlo? Por favor, ayúdenme.
La salida es:
<option value=" " selected="selected"></option> <option value=" 12345" selected="selected"> 12345</option> <option value=" abcd" selected="selected">abcd </option>El primer valor está vacío, entonces, ¿cómo puedo eliminarlo?
prueba esto
$('select option') .filter(function() { return !this.value || $.trim(this.value).length == 0; }) .remove();o
$("#select option[value=' ']").remove();