Which one of the following selectors has better performance, if not the same
$('#location_form input#id_name')$('#id_name')
I often have questions like the above pop up in my mind. I can’t really answer them because I lack the knowledge on how selection work behind the scene.
My asks:
- answer/opinions to the question above
- references that explain how jQuery selection work behind the scene
- do all javascript frameworks work in the same way as jQuery when it comes to selection?
Thanks a bunch.
With your selectors, the latter is faster, as jQuery determines you only want to select by ID and returns
document.getElementByID: https://github.com/jquery/jquery/blob/master/src/core.js#L145-165Here is the full source code: https://github.com/jquery/jquery/blob/master/src/core.js#L78-188