almost 5 years ago
We can add, remove or check classes through our angular code:
The following is the syntax for adding a class and the corresponding CSS related to that class:
HTML:
<div ng-app="addRemove" ng-controller="myCtrl"> <div id="myDiv" ng-class="staticClass">Adding and Removing class from the element.</div> <button type="button" ng-click="addClass();">Add Class</button> <button type="button" ng-click="removeClass();">Remove Class</button> <button type="button" ng-click="checkClass();">Check Class</button> </div>
Style:
.red { color:red; }
Script:
var app = angular.module("addRemove",[]); app.controller ("myCtrl", function($scope) { $scope.staticClass = []; $scope.addClass = function() { $scope.staticClass.push('red'); } $scope.removeClass = function() { $scope.staticClass.pop('red'); } $scope.checkClass = function() { if($scope.staticClass.indexOf('red') == -1) { alert('Doesn't have class red'); } else { alert('Has class red'); } } });
Hope this will help you to resolve your issue.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)