Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  120] [ 7]  / answers: 1 / hits: 67798  / 7 Years ago, wed, april 12, 2017, 12:00:00

I am using bootstrap-select for a form. I include the scripts (jquery, bootstrap-select) in the header of the HTML file.



<link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.min.css>
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.min.js></script>
<link rel=stylesheet type=text/css href=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>
<script src=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js></script>


All the select elements with class selectpicker all called correctly. Example of the select element:



<select id=test class=selectpicker>
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>


However, if I call the following script on the same page



<script>
$(document).ready(
function () {
$('#test').selectpicker('val', 'Relish')
});
</script>


I get this nasty error




$(...).selectpicker is not a function




Looking at the sources tab in Google Chrome, I see that the bootstrap-select.min.js is loaded well. Has anyone got suggestions?


More From » jquery

 Answers
6

If you have another jquery.js reference that is loading after bootstrap-select.min.js it will wipe out $(...).selectpicker function and other functions. Make sure that bootstrap-select.min.js is loaded last.


[#58180] Monday, April 10, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrencegreysons

Total Points: 674
Total Questions: 102
Total Answers: 105

Location: New Caledonia
Member since Thu, Mar 23, 2023
1 Year ago
;