Reputation: 62
Is there a way to select a DOM element (i.e. to replicate $('selector')
of jQuery) - in AngularJS using angular.element
?
Upvotes: 1
Views: 188
Reputation: 4544
The documentation for angular.element
seems pretty clear to me in that it repeatedly says "does not support selectors". On the other hand, if you've included jQuery before the DOMContentLoaded
event, then it would support selectors because it is jQuery.
However, if you're trying to select a random element from the DOM you should re-think your approach, as it is defeating the purpose of using something such as Angular.
If you're just trying to get a reference to the element on which a directive is running, then you can get that element as an argument to a function you specify as link
. See the section titled "Creating a Directive that Manipulates the DOM" here: https://docs.angularjs.org/guide/directive
Upvotes: 4