0

Is there any difference between:

var a = $('.a');
$('.b', a).click(function(){

});

and:

a.find('.b').click(function(){

});

?

rpax
  • 4,468
  • 7
  • 33
  • 57
thelolcat
  • 10,995
  • 21
  • 60
  • 102

1 Answers1

5

The first one jQuery( selector [, context ] ) that takes context is converted to second one which calls find by the jQuery. I would prefer second one.

Internally, selector context is implemented with the .find() method, so $( "span", this ) is equivalent to $( this ).find( "span" ), jQuery Docs

Adil
  • 146,340
  • 25
  • 209
  • 204