1
I have the following form:
<div class="dia" id="dia" data-id="1"><input id="1" name="diasemana[]" type="checkbox" class="dias_semana" value="1"><label for="1"> Segunda</label></div>
<div class="dia" id="dia" data-id="2"><input id="2" name="diasemana[]" type="checkbox" class="dias_semana" value="2"><label for="2"> Terça</label></div>
<div class="dia" id="dia" data-id="3"><input id="3" name="diasemana[]" type="checkbox" class="dias_semana" value="3"><label for="3"> Quarta</label></div>
<div class="dia" id="dia" data-id="4"><input id="4" name="diasemana[]" type="checkbox" class="dias_semana" value="4"><label for="4"> Quinta</label></div>
<div class="dia" id="dia" data-id="5"><input id="5" name="diasemana[]" type="checkbox" class="dias_semana" value="5"><label for="5"> Sexta</label></div>
<div class="dia" id="dia" data-id="6"><input id="6" name="diasemana[]" type="checkbox" class="dias_semana" value="6"><label for="6"> Sábado</label></div>
<div class="dia" id="dia" data-id="0"><input id="0" name="diasemana[]" type="checkbox" class="dias_semana" value="0"><label for="0"> Domingo</label></div>
With the following jQuery
$(".dia").click(function(){
var id = $(this).data('id');
$(this).addClass("selecionado");
});
Class:
.selecionado {
background-color: red;
}
When I click it adds the class, to select the div, but when I clicked to disable the checkbox, it does not return the previous color. How to do?
But the point is to uncheck.. then the background would have to return to the original..
– Sr. André Baill
@Andrébaill then what he wants is the
toggleClass
and notaddClass
. Look at my issue– Isac
Here in mine I could not adapt. It seems different to me.
– Sr. André Baill
@Andrébaill Notice that I removed the
id
of<div>
just as I changed theids
of<input>
. Confirm how you have this part in your code– Isac