JQuery Selected Option Values

I am using the Chosen jQuery plugin. I have a standard single that looks like this:

<select data-placeholder="Choose a country..." id="country">
    <option value="AF">Afghanistan</option>
    <option value="AL">Albania</option>
    <option value="DZ">Algeria</option>
</select>

With my favorites, I get something like this:

<ul class="chosen-results">
    <li class="active-result" style="" data-option-array-index="0">Afghanistan</li>
    <li class="active-result" style="" data-option-array-index="1">Albania</li>
    <li class="active-result" style="" data-option-array-index="2">Algeria</li>
</ul>

Is there an easy way to store option values ​​(AF, AL, DZ) in list items using Chosen, for example, a data value or such an attribute? I could not find it in the docs.

Thanks in advance.

+4
source share
1 answer

jquery-selected simply adds only "display: none" to your select element. Thus, you can extract all your meanings from it.

$('#yourSelectId').change(function() {
 alert(this.options[this.selectedIndex].value);
});
+5
source

All Articles