multiple option selected

Benchmark created by Sergio 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>
</select>

Test runner

Ready to run.

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


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

                        b = nCount > 1;
ready

Revisions

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