querySelector(), querySelectorAll()
The querySelector() method returns the first element that matches a specified CSS selector in the document. In order to return all the matches, use querySelectorAll() method instead.
So why people include jQuery only for use $(".someClass")? What is the difference between Javascript's document.querySelector() and jQuery $()?

First of all, jQuery works for older browsers like IE6-7 that doesn't support CSS 2.1 - 3.0 selectors.
jQuery offers you more advanced selectors like pseudo-class (i.e :selected) and more complex syntax (i.e $("> .someClass").
But of course if you think you can rely on simple selectors (classes, ids), jQuery is probably too much for you.

Also you can check performance for those two selectors: jquery-vs-native-selector-and-element-style

See also: Browser support for query selector

×
×