Get elements not having a certain class

Benchmark created by Mathias Bynens on


Description

Test case created to help me make my point on Stack Overflow.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var $container = $('<div/>').append(Array(100).join('<a></a>')).append(Array(100).join('<a class="foo"></a>'));
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Using the “attribute not equal to” selector (will fail for multiple classes)
$container.find('a[class!=foo]');
ready
Using .not()
$container.find('a').not('.foo');
ready
Using the :not() selector
$container.find('a:not(.foo)');
ready
Using .filter(':not(.foo)')
$container.find('a').filter(':not(.foo)');
ready

Revisions

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