Deselect a button (it is not a checkbox) [closed]

-1

I would be very grateful if anyone could help me with this since I am still new to this: Within a section of the page, where there are 5 buttons (come from a json), let me select several of those buttons, either one or all, have a style for active and another for inactive, then when clicked again, deselect (not disable) but stay with your inactive style.

moduloToc.controller('ctrlDatos', function($scope) {
$scope.estadoActivo = "btn btn-default";
$scope.estadoInactivo = "btn btn-info";

  $scope.cambiarEstado = function(event) {
    var idElemSel = "#" + event.target.id;
    $(document).ready(function() {
      if ($(idElemSel).click) {
        $(idElemSel).addClass('activo');
      } else {
        $(idElemSel).removeClass('inactivo');
      }
    });
  }
});

Thank you very much!

    
asked by karina mora 28.03.2017 в 19:45
source

1 answer

0

I do not know if I understood correctly but what I think you want to do is put a disabled button you can do it in the following way:

var app = angular.module('myApp',[]);

app.controller('moduloToc',['$scope', function($scope){

    $('button').on('click', function() {

       var urlid = $(this).attr('id');

       if($("#"+urlid).hasClass("active")) 
           $("#"+urlid).removeClass('active').addClass('inactive');
       else    
           $("#"+urlid).removeClass('inactive').addClass('active');

    });
}]);

The html I do not know how you have it but I did it this way:

<div ng-controller="moduloToc">
    <button id="uno" class="active">button 1</button>
    <button id="dos" class="active">button 2</button>
    <button id="tres" class="inactive">button 3</button>
</div>

here is the example

    
answered by 28.03.2017 / 20:21
source