- From: Jonas Sicking <jonas@sicking.cc>
- Date: Mon, 27 Apr 2015 19:04:27 -0700
- To: Glen Huang <curvedmark@gmail.com>
- Cc: public-webapps <public-webapps@w3.org>
On Mon, Apr 27, 2015 at 1:57 AM, Glen Huang <curvedmark@gmail.com> wrote:
> Intuitively, querySelector('.class') only needs to find the first matching
> node, whereas getElementsByClassName('.class')[0] needs to find all matching
> nodes and then return the first. The former should be a lot quicker than the
> latter. Why that's not the case?
I can't speak for other browsers, but Gecko-based browsers only search
the DOM until the first hit for getElementsByClassName('class')[0].
I'm not sure why you say that it must scan for all hits.
/ Jonas
Received on Tuesday, 28 April 2015 02:05:25 UTC