AngularJS | angular.element() Function
The angular.element() Function in AngularJS is used to initialize DOM element or HTML string as an jQuery element. If jQuery is available angular.element can be either used as an alias for jQuery function or it can be used as a function to wrap the element or string in Angular’s jqlite.
Syntax:
angular.element(element)
Where element refers to the HTML DOM element or the string to be wrapped into jQuery.
Example-1:
<!DOCTYPE html> <html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> </script> <title> angular.element() </title> </head> <body ng-app="app"> <h1 style="color:green"> GeeksforGeeks </h1> <h2> angular.element() </h2> <div ng-controller="geek"> <div ng-mouseenter="style()" id="ide" ng-mouseleave="remove()"> {{name}} </div> </div> <script> var app = angular.module("app", []); app.controller('geek', ['$scope', '$document', function($scope, $document) { $scope.name = "GeeksforGeeks"; $scope.style = function() { angular.element( $document[0].querySelector('#ide')).css({ 'color': 'white', 'background-color': 'green', 'width': '200px' }); }; $scope.remove = function() { angular.element( $document[0].querySelector('#ide')).css({ 'color': 'black', 'background-color': 'white' }); }; } ]); </script> </body> </html> |
Output:
Before mouseenter:

After mouseenter:

Example-2:
<!DOCTYPE html> <html> <head> <script src= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"> </script> <title> angular.element() </title> </head> <body ng-app="app" style="text-align:Center"> <h1 style="color:green"> GeeksforGeeks </h1> <h2> angular.element() </h2> <div ng-controller="geek"> <input type="text" id="text" ng-model="myVal" /> <button ng-click="getVal()"> Click me! </button> <br /> <br><b>You typed:</b> {{value}} </div> <script> var app = angular.module("app", []); app.controller('geek', ['$scope', '$document', function($scope, $document) { $scope.myVal = ""; $scope.getVal = function() { $scope.value = angular.element( $document[0].querySelector( '#text')).val(); } }]); </script> </body> </html> |
Output:
Before Input:

After Input:

Recommended Posts:
- PHP | imagecreatetruecolor() Function
- p5.js | year() function
- D3.js | d3.utcTuesdays() Function
- PHP | Ds\Sequence last() Function
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- D3.js | d3.map.set() Function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- D3.js | d3.bisectLeft() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | SimpleXMLElement children() Function
- AngularJS | ng-show Directive
- PHP | is_numeric() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



