3

I was wondering which of both methods is faster:

Selecting the container and the form itself at in one statement:

jQuery $('#submitForm form')

or using jQuery's .find() selector:

jQuery $('#submitForm').find('form')
Ivan Sieder
  • 934
  • 1
  • 10
  • 24

1 Answers1

3

The .find() approach is faster because the first selection is handled without going through the Sizzle selector engine – ID-only selections are handled using document.getElementById(), which is extremely fast because it is native to the browser.

So

jQuery $('#submitForm').find('form')

Is Faster than

jQuery $('#submitForm form')

Selector optimization is less important than it used to be, as more browsers implement document.querySelectorAll() and the burden of selection shifts from jQuery to the browser.

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68