I have several div
elements on a webpage.
Each div
contains a button!
- When the button is clicked for the first time:
- The border color of the
div
will change to blue (indicating thediv
is now selected). - The "ok" button will be hidden (leaving only the selected
div
visible).
- The border color of the
Clicking anywhere inside the
div
for the second time will deselect it:- The border will return to its original black color.
- The button will become visible again.
By clicking the select all button for the first time, the
div
should be selected. Clicking it again will unselect thediv
. (Toggle action)
How can I achieve this functionality using AngularJS.
function MainCtrl($scope) {
$scope.addBackground = function () {
angular.element(document.querySelector('.container')).addClass('selectedBorder');
angular.element(document.getElementById('okBtn')).css('display','none');
};
};
.container{
width:30%;
height:100px;
border:1px solid black;
margin:10%;
}
button.btn.btn-primary{
margin-top:10%;
margin-left: 40%;
}
.selectedBorder{
border: 3px solid blue;
}
<div id="myAngularApp" title="Angular Scope" ng-app ng-controller="MainCtrl">
<div class="container">
<button id="okBtn" class="btn btn-primary" ng-click="addBackground()">ok</button>
</div>
</div>