When accessing the page, the titles are color = blue
When you click on the title, the color changes to color = red (and opens content)
But when the title closes back to color = blue
I need to: When clicking on the title change to the color = red and when you click again when you leave color = green
Thanks for the help.
JQ321
$(document).ready(function(){
$('#abre').on('click' , function(){ // abre tudo
$('.titulo .conteudo').show();
});
$('#fecha').on('click' , function(){ // fecha tudo
$('.titulo .conteudo').hide();
});
$('.titulo').on('click' , function(){ // abre/fecha cada titulo
var id = $(this).attr('id');
$('#tit'+id).toggle();
var classes = ['red','green']; // Nomes das classes CSS
this.className = classes[($.inArray(this.className, classes)+1)%classes.length]; // Altera a class conforme o clique
});
});
CSS
.titulo {color:blue}
.red {color:red}
.green {color:green}
.conteudo {display: none;}
@media(min-width:800px){
.lista-titulos {
-webkit-column-count: 2;
-moz-column-count: 2;
column-count: 2;
}
.titulo,.mostra{
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
break-inside: avoid;
}
}
@media(min-width:1024px){
.titulo {cursor:pointer}
.titulo:hover {background:yellow}
PHP/HTML5
<div class="lista-titulos">
BD select while...
<div class="titulo" id="<?=$id?>"><span class="tit<?=$id?>"><?=$perg?>/span>
<span id="tit<?=$id?>" class="conteudo">
<div class="mostra">TEXTO</div>
</span>
</div>
</div>
NO RODAPÉ
<div><button type="button" id="abre">abrir tudo</button> <button type="button" id="fecha">fechar tudo</button></div>