AngularJS Tutorial - Mouse hover to change style








The following code shows how to use Mouse hover event to change style.

Example


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<style type='text/css'>
.red {<!--from  w ww  .j  a  va 2s.  c om-->
    background-color: red;
}

.italic {
    font-style: italic;
    color: black;
}
</style>
  
</head>
<body>
  <div ng-app>
    <div 
     class="italic" 
     ng-class="{red: hover}" 
     ng-mouseenter="hover = true"
     ng-mouseleave="hover = false">
         Hover me.
    </div>
</div>
</body>
</html>

The code above is rendered as follows: