views:

50

answers:

1

Why is id selector faster than class selector in jQuery?

+8  A: 

The fastest selector in jQuery is the ID selector ($('#someid')). This is because it maps directly to a native JavaScript method, getElementById().

XGreen
... and that method is bound to be faster than walking through an array of elements of a certain class.
Pekka