I have the following setup:
var el = $("#overParent");
// Do whatever with el here.
var cls = $(".valueElement", "#parent"); // Get elements with class valueElement inside element with id parent
// Do whatever
This is working but I was wondering if I can make this faster. I know that #parent is an element inside the #overParent which is already selected. Can I somehow use this to scan only the el #overparent for #parent then get the elements with the specified class?
Something like: $(".valueElement", "#parent", el) but according to documentation $ takes only 2 parameters.
Just stick with the regular id selector:
It’s still the fastest, even if you already have the parent element selected: http://jsperf.com/id-test-123
I’m just guessing here, but I think browsers use a lookup table to find elements by their id attribute.