Created
October 2, 2013 10:52
-
-
Save mrosati84/6791964 to your computer and use it in GitHub Desktop.
Simple toggleClass implemented in AngularJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
<style> | |
.is-active { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<div ng-app="myApp"> | |
<div ng-controller="MyCtrl"> | |
<ul> | |
<li ng-click="toggleClass($event, 'is-active')">Cliccami</li> | |
<li ng-click="toggleClass($event)">Cliccami</li> | |
<li ng-click="toggleClass($event, 'is-culo')">Cliccami</li> | |
<li ng-click="toggleClass($event, 'is-active')">Cliccami</li> | |
<li ng-click="toggleClass($event, 'is-active')">Cliccami</li> | |
</ul> | |
</div> | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<script> | |
var myApp = angular.module('myApp', []); | |
function MyCtrl ($scope) { | |
$scope.toggleClass = function($event, className) { | |
className = className || 'is-open'; | |
$($event.target).toggleClass(className); | |
}; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment