AngularJS | ng-mouseover Directive

The ng-mouseover Directive in AngularJS is used to apply custom behavior when an mouseover event occurs on a specific HTML element. It can be used to show popup alert when mouse moves over a specific element. It is supported by all HTML elements.

Syntax:

<element ng-mouseover="expression"> Contents... </element>

Example 1: This example uses ng-mouseover Directive to display content when mouse move over the element.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>ng-mouseover Directive</title>
  
    <script src=
    </script>
  
    <style type="text/css">
        .geek {
            border: 1px solid black;
            width: 400px;
            background-color: green;
            border-radius: 4px;
            height: 20px;
            color: white;
        }
    </style>
</head>
  
<body ng-app="">
    <center>
        <h1 style="color:green">
            GeeksforGeeks
        </h1>
          
        <h2>ng-mouseover Directive</h2>
          
        <div ng-init="geek=false">
          
            <button ng-mouseover="geek=true" 
                    ng-mouseleave="geek=false">
                Mouse over me!
            </button>
              
            <br><br>
              
            <div class="geek" ng-show="geek">
                GeeksforGeeks is the computer 
                science portal for geeks.
            </div>
        </div>
    </center>
</body>
  
</html>

chevron_right


Output:
Before mouseover the element:
ngmousedown
After mouseover the element:
ngmousedown

Example 2: This example uses ng-mouseover Directive to display an alert message when mouse move over element.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
      
<head>
    <title>ng-mouseover Directive</title>
  
    <script src=
    </script>
</head>
  
<body  ng-app="app" style="text-align:center">
      
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>ng-mouseover Directive</h2>
   
    <div ng-controller="app">
        Input: <input type="text" ng-mouseover="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 mouseover the element:
ngmousedown
After mouseover the element:
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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.