Selectors in jQuery
categories: jquery
Just a note to self: Quick Tip - Optimizing DOM Traversal. Avoid bare classname selectors like $('.foo') when possible; qualify them with an element type or, ideally, the ID of a parent element: $('div.foo') or $('#bar .foo').
March 14th, 2008 at 3:41 pm
The great fun of optimizations like that: Once a browser implements document.getElementsByClassName, the plain-class version is most likely way faster than your qualified one. And less flexible. Can’t just change a span to a div when it breaks your optimized selector.