thelolcat
thelolcat

Reputation: 11545

Best way to select a descendant element

Is there any difference between:

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

});

and:

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

});

?

Upvotes: 0

Views: 81

Answers (1)

Adil
Adil

Reputation: 148120

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

Upvotes: 6

Related Questions