AngularJS | ng-mouseenter Directive

The ng-mouseenter directive in AngularJS is used to apply custom behaviour when a mouse-enter event occurs on a specific HTML element. It can be used to show popup alert when mouse enters a specific position in a HTML element. It is supported by all HTML elements.

Syntax:

 <element ng-mouseenter="expression"> content ... </element> 

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    angular.min.js"></script>
    <head>
        <title>ng-mouseenter Directive</title>
        </head>
    <style type="text/css">
        .outerDiv {
            width: 100px;
            height: 100px;
            background-color: green;
            margin-left:40px;
        }
    </style>
    <body ng-app style="padding:30px">
            <h1 style="color:green">GeeksforGeeks</h1>
            <h2>ng-mouseenter Directive</h2>
            <div class="outerDiv" ng-mouseenter="oc=oc+1;outer=true" 
                ng-mouseleave="outer=false">
                <p style="text-align:center;color:white">Mouse 
                     {{outer==true?'Enter':'Out'}}</p>
                <br />
  
                <p style="text-align:center;color:white">
               {{oc}}<br /></p>
            </div>
    </body>
</html>

chevron_right


Output:
Before Mouseenter:
ngmousedown
After Mouseenter:
ngmousedown

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    angular.min.js"></script>
    <head>
        <title>ng-mouseenter Directive</title>
       </head>
     <body  ng-app="app" style="text-align:center">
        <h1 style="color:green">GeeksforGeeks</h1>
        <h2>ng-mouseenter Directive</h2>
  
        <div ng-controller="app">
            Input: <input type="text" ng-mouseenter="alert()" 
                ng-model="click" />
        </div>
        <script>
            var app = angular.module("app", []);
            app.controller('app', ['$scope', function ($scope) {
                $scope.click = 'geeksforgeeks';
                $scope.alert = function () {
                    alert($scope.click);
                }
            }]);
        </script>
    </body>
</html>

chevron_right


Output:
Before Mouseenter:
ngmousedown
After Mouseenter:
ngmousedown



My Personal Notes arrow_drop_up


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.