I am trying to change the color of the specific heading in AngularJS. My issue is that there are multiple headings with the same class in it and I would like to change the color of the one that is clicked only. Currently, I have tried:
HTML:
<div class="row">
<div class="span6">
<div class="heading">Heading 1</div>
</div>
<div class="span1">
<i class="pull-right" expand="check" collapse="close"></i>
</div>
</div>
JS:
scope.setExpandCollapse = function () {
if (scope.expand && scope.collapse) {
if (isOpen) {
angular.element(document.querySelectorAll('.heading')).removeClass('color-change');
} else {
angular.element(document.querySelectorAll('.heading')).addClass('color-change');
}
}
};
The issue is that it changes color of all the headings due to querySelectorAll. Is there a way for me to do this without changing my HTML?
querySelectorAllis a NodeList which you can loop through... Try a for each or for in ondocument.querySelectorAll('.heading')