This question already has an answer here:
I'm so confused. I'm just trying to test out a jquery (simpleselect) and got it working fine on jquery, but then when I upload it to my server... totally doesn't work! I swear its the same code but maybe fresh eyes can help. What am I missing here?
This is the code I uploaded:
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://smartieparts.com/bootstrap/includes/templates/bootstrap/css/stylesheet_jquery.simpleselect.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://smartieparts.com/bootstrap/includes/templates/bootstrap/jscript/jscript_jquery.simpleselect.min.js"></script>
<script type="text/javascript">
$("#currency-select").simpleselect({
fadingDuration: 500,
containerMargin: 100,
displayContainerInside: "document"
});
</script>
</head>
<body id="indexHomeBody">
<select name="currency" id="currency-select">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="CAD">CAD</option>
<option value="AUD">AUD</option>
<option value="CHF">CHF</option>
<option value="CZK">CZK</option>
<option value="DKK">DKK</option>
<option value="HKD">HKD</option>
<option value="JPY">JPY</option>
<option value="NZD">NZD</option>
<option value="NOK">NOK</option>
<option value="PLN">PLN</option>
<option value="SGD" selected="selected">SGD</option>
<option value="SEK">SEK</option>
<option value="ILS">ILS</option>
<option value="MXN">MXN</option>
<option value="TWD">TWD</option>
<option value="PHP">PHP</option>
<option value="THB">THB</option>
</select>
</body>
</html>
And here is the JSfiddle
Note that the JSfiddle has external css and js resources that I exactly copy/pasted from the code above.
On the JSfiddle page, the drop down is formatted and has a fade effect. On my server, it is somewhat formatted and has no fade.
I've uploaded the file to my server so you can check. Link
Set document-ready
Read more about it
Script in
head
tag doesn't know anything about Your DOM when executed. You should move<script>
before closing</body>
tag (after DOM is loaded), o wrap Your code in document-ready handler:Moving script before closing
</body>
tag is better IMHO.The script you wrote simply fires before any of the elements have been loaded. This way jQuery doesn't find
#currency-select
as it doesn't exist yet. To solve this you have two ways:1) Execute this script after the onLoad event has been triggered. You can do it with the jQuery like this
2) You can move your script tag right before the closing tag
</body>
This way the scripts are handled after the elements of the page. And this one would be a suggested option for all your scripts.Ref
Wrap your code in document-ready handler.
Additionally, is you check the console window: you can see that some files are not loading. Correct them and everything will work fine.
![enter image description here](https://i.stack.imgur.com/Bjc5l.png)