Difference between element.find("elm") and element[0].querySelector("elm")


#1

Hello :smiley:

What’s the best way to find an element inside a directive?

element.find(“elm”)?
element[0].querySelector(“elm”)?

I’ve seen in the ionic lib and sometimes they use element.find, but most of the times they use element[0].querySelector.

I always use .find, but i want’ to know the difference, I’ve tried to search for it, but there are several opinions about the two ways, but none could clarify my doubt.

So if someone could explain to me the difference between the both, i would be glad.

EDITED:
I think i got it!

element.find in jqlite only allows looking for tag names, if you want to find id’s or classes, you will have to use element.querySelector, this without jQuery lib. Correct me if i’m wrong.

Still is best to use element.find when looking for tag names instead querySelector?
Why?

Regards,
pcagica.


#2

element.find would be better… because angular restricted the selectors to minify dom-manipulations.
In a perfect world you do only dom-manipulation on the element you set on your directive.