• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

which is faster

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the two is faster or efficient when selecting the element: I need to get the innermost div (marked with innerDiv class)

var element = document.getElementById("main");
var elementNeeded = element.querySelector(".innerDiv");

or:

var elementNeeded = document.querySelector("#main .innerDiv");

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It'd be easy enough to make timing tests to find out (I talk about this in chapter 2 of Secrets of the JavaScript Ninja) but I'd ask why you are interested unless there are demonstrable performance issues with one or the other. Just curiosity?

The results are also likely to be browser-dependent.
reply
    Bookmark Topic Watch Topic
  • New Topic