Comparing jQuery's .filter VS .not VS :not (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<p>
  Single P
</p>
<p class="first-class">
  P with class
</p>
<p id="first-id">
  P with it
</p>
<p class="second-class" id="second-id">
  P with class and ID
</p>

Test runner

Ready to run.

Testing in
TestOps/sec
Using .filter
$('p').filter(function(index) {
  if (!$(this).attr("class")) {
    return true;
  }
});
ready
Using .not
$('p').not(function(index) {
  if ($(this).attr("class")) {
    return true;
  }
});
ready
Using :not
$('p:not([class])');
ready

Revisions

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