simple removeClass vs jquery removeClass (v2)

Revision 2 of this benchmark created by select from dom on


Preparation HTML

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

<div id="foo">300%</div>
<div id="test" class="class_a class_b class_c"></div>

<script type="text/javascript">
(function( $ ){
    $.fn.removeClass2 = function( className ) {  
        return this.each(function() {
            $this = $(this).get(0);
            if ( $this.className ) {
                var classList = $this.className.split(' ');
                for ( var i = 0; i < classList.length; i++ ) {
                    if(classList[i] == className) {
                        classList.splice(i, 1);
                    }
                }
                $this.className = classList.join(' ');
            }
        });
    };
})( jQuery );

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jquery removeClass
$('#test').removeClass();
ready
Simplier jquery removeClass
$('#test').removeClass2('class_a');
ready
attr
$('#test').removeAttr("class");
ready

Revisions

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