0

Is there any difference between:

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

});

and:

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

});

?

rpax
  • 4,363
  • 7
  • 31
  • 55
thelolcat
  • 10,155
  • 19
  • 59
  • 100

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
  • 143,427
  • 25
  • 201
  • 198