Angularjs Dynamically Add Class Remove Class with Toggle Class

Angularjs Dynamically Add Class Remove Class with Toggle Class

In this Post We Will Explain About is Angularjs Dynamically Add Class Remove Class with Toggle Class With Example and Demo.Welcome on infinityknow.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Add Class, Remove Class or Toggle Class to div using AngularJSExample

In this post we will show you Best way to implement javascript – How to add and remove class with AngularJS, hear for javascript – adding and removing classes in angularJs using ng-clickwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

READ :  Vuejs Submit serialized form data - vue serialize form

AngularJS is Simple providing using Style ng-class to manipulate every classes of HTML an elements.

Angularjs Add class Example using ng-class :

 
$scope.liveClass = [];
$scope.liveClass.push('green');

Angularjs Remove class Example using ng-class :

$scope.liveClass = [];
$scope.liveClass.pop('green');

Angularjs Add class Example using ng-class with JSON

 $scope.liveClass = {green:false};
$scope.addClass = function() {
   $scope.liveClass.green = true;
}

Angularjs Remove class Example using ng-class with JSON

 $scope.liveClass = {green:false};
$scope.removeClass = function() {
    $scope.liveClass.green = false;
}

Angularjs Toggle class using ng-class with JSON Example

 $scope.liveClass = {green:false};
$scope.toggleClass = function() {
     $scope.liveClass.green = !$scope.liveClass.green;
};

Angularjs Add class to HTML an elemnt :

 var mytemp_var = angular.element( document.querySelector( '#liveweb_id' ) );
mytemp_var.addClass('green');     

Angularjs Remove class from HTML an element :

 var mytemp_var = angular.element( document.querySelector( '#liveweb_id' ) );
mytemp_var.removeClass('green');     

Angularjs Toggle class to HTML an element

var mytemp_var = angular.element( document.querySelector( '#liveweb_id' ) );
mytemp_var.toggleClass('green');    

Find whether get HTML element has Add particular Class

 var mytemp_var = angular.element( document.querySelector( '#liveweb_id' ) );
if(mytemp_var.hasClass('green')) {
  alert('success has class green');
}    

Example

READ :  Angular Datepicker Directive Example with Demo

I hope you have Got What is AngularJS Add Class Remove Class or Toggle Class And how it works.I would Like to have FeadBack From My Blog(infinityknow.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(infinityknow.com) Are Most Always Welcome.

Add a Comment

Your email address will not be published. Required fields are marked *