Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 22940  / 10 Years ago, sat, april 26, 2014, 12:00:00

I have the following select/option



<select class=bs-select form-control>
<option value=AL>Alabama</option>
<option value=WY>Wyoming</option>
</select>


In my script section, I have this, which works fine. The styles are being applied



$(document).ready(function () {
$('.bs-select').selectpicker();
});


I have a button that does this:



$('.bs-select').append($('<option>', {
value: 0,
text: test
}));


However my select list isn't refreshed.



I tried adding



$('.bs-select').selectpicker();


after the append but it still doesn't work.



My select list gets refreshed if I remove the $('.bs-select').selectpicker() in $(document).ready



How can I get my list to refresh after adding an item?


More From » jquery

 Answers
92

Use refresh after adding new option



$('.bs-select').selectpicker('refresh');

[#71291] Thursday, April 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
magaly

Total Points: 524
Total Questions: 96
Total Answers: 89

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
;