We can get class list by using JavaScript element. Here we can get JavaScript Element from angular element with $event.target. In this example, we are going find out the classes of button element which triggers click event.

Markup

<button class="btn btn1 btn2" ng-click="getClassList($event)">
  Get Class List
</button>

Script

$scope.getClassList = function($event) {
      var classList = $event.target.className.split(/\s+/);
      alert(classList);
      for (var i = 0; i < classList.length; i++) {
        if (classList[i] === 'someClass') {
          //do something
        }
      }
}

0 comments:

Blogroll

Follow this blog by Email

Popular Posts