find vs context 1 vs context 2

Edit on GitHub

Setup

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

<article id="article">
<p>A test</p>
<p class="iframe"><iframe></iframe></p>
<p>This is text</p>
</article>

      

      <script>

        Benchmark.prototype.setup = function() {

          
  
  

        
  };


      
</script>

Tests

  • find

    var hasFrame = $('#article').find('.iframe').length > 0 ? true : false;
  • context 1

    var hasFrame = $('.iframe', '#article').length > 0 ? true : false;
  • context 2

    var hasFrame = $('#article .iframe').length > 0 ? true : false;