Given how optimized jquery is, does anyone understand why something as simple as getting an element by id would be so much slower than Dom methods?
I'm surprised by the number of comments like this. jQuery has to parse the selector and figure out that it's of the form "#id". This requires running a regular expression. A lot more is happening. The whole jQuery call from start to finish takes 2.85 microseconds, in what is presumably a real benchmark, but microbenchmarks like this are hard to interpret and basically meaningless. But yes, if your app needs to do a b…
The sentiment is borne out by the facts when you dig a little deeper. Just calling document.getElementById without using the return value does not actually dig into the DOM and find the element according to this comment: http://news.ycombinator.com/item?id=4436438