How to add a class to a div when it is active, so that it changes color?

2

I'm making a Bootstrap-based website, in which I have a portfolio zone, in which thumbnails open a respective collapsible DIV. I need when a collapsible DIV is open, the respective thumbnail changes its CSS formatting, in this case color. I tried to add a class to this ".cliente_activo" call through my Javascript, but since I am not an expert in this last language, I did not succeed. I would appreciate if you could help me.

My prototype:

FIDDLE

    
asked by anonymous 28.03.2014 / 18:35

1 answer

7

I was very close, I made a change and added a line to remove the classes that had been added to other elements

Test like this:

 $('.panel-heading').on('click', function () {
     var self = this;
     $('.cliente_activo').removeClass('cliente_activo'); // remover a classe em todos os elementos que a tiverem
     $(this).addClass('cliente_activo'); // adicionar a a classe ao elemento que recebeu o clique
     if (!bigMedia) {
         $('.panel-collapse').slideUp();
         $(this).parent().next().slideToggle('collapse');
         $(this).addClass('cliente_activo');
     } else {
         if (conteudo) {
             conteudo.slideToggle(function () {
                 $(this).remove();
                 abrirFechar(self);
                 // retirei daqui
             })
         } else abrirFechar(self);
     }

 });

Example

You could also use the aberto you already have in the code, example

    
28.03.2014 / 18:39