Simply using $('select[class*="selectize"] option')
worked for me. I used *=
because I often use multiple classes at a time on elements (more on jQuery selectors/wildcards at w3schools.com). Otherwise, if using id or name, I would use $('select[id="selectize-id"] option')
or $('select[name="selectize-name"] option')
respectively.
Then, to get the option value, I add on .text()
and to get the option key I add on .val()
.
Example
If I have a list of countries and "usa" is the currently selected value with "United States" being the currently viewable text, I would do the following:
$('select[class*="selectize"] option').val()
to return "usa"
$('select[class*="selectize"] option').text()
to return "United States"
Possible Alternative
Simply using the basic id selector -- as in $('#selectize-id option')
-- did not work. However, using the basic class selector -- as in $('.selectize-class option')
-- did seem to work (more on attribute selectors on w3schools.com). Perhaps someone can comment on the difference between the two ($('#someId)
vs $('element[id="someId"]')
) that causes this.