$( document ).ready(function() {
var options = $('select#myshp_search_field_7 option');
var arr = options.map(function(_, o) {
return {
t: $(o).text(),
v: o.value
};
}).get();
arr.sort(function(o1, o2) {
return o1.t > o2.t ? 1 : o1.t < o2.t ? -1 : 0;
});
options.each(function(i, o) {
console.log(i);
o.value = arr[i].v;
$(o).text(arr[i].t);
});
});
So this sorts my select field but it only sorts on the first digit(number)>
<select id='myshp_search_field_7'>
<option value='10'>10</option>
<option value='5'>5</option>
<option value='3'>3 </option>
<option value='11'>11 </option>
</select>
The result of the code is : 10 , 11 , 3, 5
But i want it to be : 3, 5 , 10, 11