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

Revision 2 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") && !$(this).attr("id")) {
    return true;
  }
  return false;
});
ready
Using .not
$('p').not(function(index) {
  if (!$(this).attr("class") && !$(this).attr("id")) {
    return false;
  }
  return true;
});
ready
Using :not
$('p:not([id],[class])');
ready

Revisions

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