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')
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')
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.