angular-element-3

 

In this example of angular element, CSS will be apply on mouse enter and removed on mouse leave. See the code snippet:

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome in the AngularJS</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="elementController"> <div ng-mouseenter="applyCss()" id="myDiv" ng-mouseleave="removeCss()"> {{name}} </div> </div> <script> var app = angular.module("app", []); app.controller('elementController', ['$scope', '$document', function ($scope, $document) { $scope.name = "LearnKode"; $scope.applyCss = function () { angular.element($document[0].querySelector('#myDiv')).css({ 'color': 'white', 'background-color': 'red' }); }; $scope.removeCss = function () { angular.element($document[0].querySelector('#myDiv')).css({ 'color': 'black', 'background-color': 'white' }); }; }]); </script> </body> </html>
Output