I often use .class
to select a single html element. However, this is not correct. I've read somewhere that using #id
is the optimal approach when using jQuery. How much faster is using #id
instead of .class
when trying to select a single element?
Asked
Active
Viewed 403 times
1

plr108
- 1,201
- 11
- 16
-
2check http://stackoverflow.com/questions/6460644/in-jquery-is-selecting-by-class-or-id-faster-than-selecting-by-some-other-attri – nunoarruda Jan 30 '15 at 00:43
-
2That's completely browser implementation dependent. – c-smile Jan 30 '15 at 00:43
-
2I would think the performance is negligible but Id is probably faster because once it would find it, it would stop looking. I think its better to just use Id's when you want a single element, classes when you need multiple elements because it makes nicer code. – mattfetz Jan 30 '15 at 00:53
1 Answers
4
-
2This would make sense because instead of looking for every instance like you would with a class you would be looking for for a single element and then stopping. – mattfetz Jan 30 '15 at 00:56