Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between $('.className > button') and $('.className').children('button')?

In jQuery is there any difference between

$('.className > button')

and

$('.className').children('button')

Or are these just alternate syntaxes to get the same thing?

like image 688
Adam Solomon Avatar asked Aug 29 '15 11:08

Adam Solomon


1 Answers

Not in terms of what you'll actually end up with, but the first one can be offloaded in its entirety to the browser's built-in CSS selection engine, whereas the second one requires jQuery to do more work and involves more object creation and cleanup. It's unlikely to matter unless you're doing this with a lot of elements in, say, a mousemove handler, though, if even then...

like image 134
T.J. Crowder Avatar answered Nov 10 '22 14:11

T.J. Crowder