multiple option selected (v2)

Revision 2 of this benchmark created by Josep on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<select id="sel" size="3" multiple="multiple" name="sel[]">
        <option selected="selected" value="-1">---</option>
        <option value="1">A</option>
        <option value="2">B</option>
        <option value="3">C</option>
        <option value="4">D</option>
        <option value="5">E</option>
        <option value="6">F</option>
        <option value="7">G</option>
        <option value="8">H</option>
        <option value="9">I</option>
        <option value="10">J</option>
        <option value="11">K</option>
        <option value="12">L</option>
        <option value="13">M</option>
</select>

Setup

var targetSelect = document.getElementById('sel');

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery
var bMultipleselected = $( targetSelect ).val().length > 1;
ready
Native
                        var aOptions = targetSelect.options,
                                nIndex = aOptions.length,
                                nCount = 0, b;


                        while ( nIndex-- && nCount <= 1 )
                        {
                                if( aOptions[nIndex].selected )
                                {
                                        nCount++;
                                }
                        }

                        b = nCount > 1;
ready
jQuery 2
b = $("option:selected", targetSelect).length > 1;
ready
QSL selected
b = targetSelect.querySelectorAll('option[selected=selected]').length > 1;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.