Difference between selector in jquery

Until today, I considered these two selectors as one and the same, I think they perform the same action, but today I ran into a problem when they behave differently. I want to know what is the difference between these selectors. demo

$('.test p:first');

$('.test').find('p:first');
+4
source share
3 answers

findwill execute the passed selector for each item that exists in the called collection. So, looking at your code:

$('.test p:first')
Performed

$('.test p:first'). This will return one item pthat will be the first in all items .test.

Unlike:

$('.test').find('p:first')

$('.test'). 3 .test ( html ). find . , .text p. - 3 .

+4

,

$('.test').find('p:first') - p:first .test. .

$('.test p:first') - p:first p, .test. .

+2

, $('.test p:first') p ALL .test.

$('.test').find('p:first') p EACH .test.

+1

All Articles