some posts have suggested #id is faster than .class in Jquery based on speed test or #id and .class have been optimized for browsers. However, I suppose it should be down to how it traverse along the HTML Dom tree.
For example:
P
|
---------------
| |
C1 C2
| |
------- ------
| | | |
C11 C12 C21 C22
For find c12, the path is P-C1-C11-C1-C12 (it could be different path depending on the structure, but it's I can remember now)
no matter c12 is class or id, it will be the same path, which means the same performance for $('#C12') or $('P C1 .C12')
My first question is if my understanding is right? Question 2: I keep thinking about performance of one to another and minimize my codes to put duplication together into functions, on the other hand, it takes time. Should I keep doing it or just to make it work first and change it later?
Thanks.