The reason why it's working also in the first way is that you included jQuery before AngularJS, so actually when you call angular.element angular returns to you an instance of $, and you are able to use angular.element with selectors too.
Otherwise AngularJS has a built-in version of jQuery that is jQlite, and you need to pass the HTML element inside angular.element in order to get back a jQlite object, that is a standard jQlite object with some more properties added by AngularJS.
This snippet includes jQuery after AngularJS. In this case that selector doesn't work.
console.log(angular.element('#test'));
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="test"> ciao </div>
This snippet includes jQuery before instead, and the selector actually works:
console.log(angular.element('#test'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div id="test"> hello </div>
p.s. I don't know if it is an issue with the actually code snippet engine here in stack overflow, because I usually use angular.element passing the HTML element, but I noticed a really decrease of performances using directly the selector with angular.element. The following snippet will use the angular.element passing the HTML even if jQuery is included before AngularJS, and it seems to run really really faster than the previous one. You can compare them. But again, maybe it just depends on the current snippet engine in SO
console.log(angular.element(document.querySelector('#test')));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div id="test"> hello </div>
angular.element( '#divID');. Are you sure that you really retrieve the element correctly?angular.elementis equivalent tojQuerybecause angular is built on top of jQuery.