I have elements in my page with ids like child_0_1_1_0.
It is formed with four variables, so there can be maximum of 16 child elements.
What will be the best way to select element:
Trade off is between touching the DOM Vs string operations.
Which one is better?
Touching the DOM is almost always the slowest thing you'll do in JavaScript. String operations would be your best bet.
With that said, the difference for most tasks will be insignificant. Don't worry about optimizing your code too early; if n-th child operations allow you to code more easily and cleanly, then use them! If they prove too slow in the future, address it then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With