I have a couple of buttons that are dynamically placed in an ng-repeat. I want to be able to "select" a button. By that I mean when I click on one, its CSS changes. When I click another one, the first button gets its original CSS back and the new button becomes selected. Can anyone help me out?
HTML:
<button ng-repeat="answer in regular_answers" ng-attr-id="{{'answer' + answer.regularAnswerId}}" class="button button-balanced button-block" ng-click="selectAnswer(answer)">
{{answer.answer}}
</button>
JS:
$scope.selectAnswer = function (answer) {
if (document.getElementById('answer' + answer.regularAnswerId).hasClass('button-selected')) {
document.getElementById('answer' + answer.regularAnswerId).removeClass('button-selected');
document.getElementById('answer' + answer.regularAnswerId).addClass('button-balanced');
}
else {
document.getElementById('answer' + answer.regularAnswerId).removeClass('button-balanced');
document.getElementById('answer' + answer.regularAnswerId).addClass('button-selected');
}
}