all articles

zepto does not support selector(:selector, :checked)

2016-09-16 @sunderls

zepto select check option js


zepto seems not to support ':selected' selector to get selected option of <option>.

jQuery supports both $(':checked'), $(':selected') to accomplish this, but zepto only support ':checked';

Well on the other hand,on some Android(4.3, 4.4), $(':checked') is not working, neither will $select.children().filter(':checked');

for Zepto, $select.val() will get us the right value, but how can we get the selected option from <select>, for example to get the label by $.text()?


seems zepto does less workarounds than jquery, we have to do it ourself

        var getSelectedOption = function($select){
            var $allOptions = $select.children(),
                $selectedOption = undefined;

                    $selectedOption = $(this);
                    return false;

            return $selectedOption || $allOptions.eq(0);