-3

I am new to jQuery. I learned jQuery selector, which is used for selecting DOM elements. But I don't understand how it internally finds the DOM element. If I give something like $("#pelement") or $(".pclass") how does jQuery find the DOM element?

Does use document.getElementById() or something? How can I understand this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Lolly
  • 34,250
  • 42
  • 115
  • 150

1 Answers1

2

It's just a library, so yes, if an ID is what you're looking for, it uses document.getElementById()

If querySelector() is available in the browser, it also uses that, otherwise it probably uses getElementsByClassName() for classes.

In other words it takes what ever is available in the browser and uses the most efficient one, and abstracts that so that you can use CSS selectors in your code without having to think about stuff like what the browser supports, and what method to use etc.

adeneo
  • 312,895
  • 29
  • 395
  • 388