javascript - Selecting a select option with jQuery not working -


i trying use jquery set 1 of options of dropdown menu selected one. i've tried: (the code within document ready block)

if($.cookie("regio")) {     $('#regio option[value="'+ $.cookie("regio") +'"]').prop('selected', true); } 

this html code:

<select class="form-control" id="regio"> <!-- here options --> </select> 

nothing happens after this. have debugged values using firebug , cookie correspond 1 of select values. problem?

$('#regio').val($.cookie("regio")) 

example in snippet:

$("select").val("second")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>    <select>    <option value="first">first option</option>    <option value="second">second option</option>    <option value="third">third option</option>    <option value="forth">forth option</option>  </select>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -