selectize.js
selectize.js copied to clipboard
iterate over options
Hi, i can't understand how i can iterate over all options element. I'm sorry, it must be a very basic function, but maybe is not too much intuitive! can someone help me?
var $select = $('select').selectize({...});
// <option> elements
var $options = $('option', $select);
// selectize options (an object)
var options = $select[0].selectize.options;
Just in case anyone else finds this question while attempting to iterate over the options object. Assuming brianreavis' code above, you can iterate over the "options" variable using: Object.keys(options).
for(key in $select[0].selectize.options){
console.log($select[0].selectize.options[key]);
}