Chciałbym połączyć ze sobą 3 funkcje, ponieważ czuję, że jest to możliwe, jednak nie mam pomysłu na to, jak to zrobić. To są funkcje jakie chciałbym połączyć:
$("#check1").click(function(){
if (document.getElementById('check1').checked)
{
$(".location-type1").removeClass("display-none")
}
else {
$(".location-type1").addClass("display-none");
}
});
$("#check2").click(function(){
if (document.getElementById('check2').checked)
{
$(".location-type2").removeClass("display-none")
}
else {
$(".location-type2").addClass("display-none");
}
$("#check3").click(function(){
if (document.getElementById('check3').checked)
{
$(".location-type3").removeClass("display-none")
}
else {
$(".location-type3").addClass("display-none");
}
});
A tutaj moje rozwiązanie:
$("#check3, #check2, #check1").click(function () {
console.log($(this).data("value"));
if ($(this).data("value") === 1) {
if ($("#check1").checked) {
$(".location-type1").removeClass("display-none");
}
else {
$(".location-type1").addClass("display-none");
}
}
else if ($(this).data("value") === 2) {
if ($("#check2").checked) {
$(".location-type2").removeClass("display-none");
}
else {
$(".location-type2").addClass("display-none");
}
}
else {
if ($("#check3").checked) {
$(".location-type3").removeClass("display-none");
}
else {
$(".location-type3").addClass("display-none");
}
}
});
Niestety, jedyne co ono powoduje, to znikanie danego location-type, a jego pojawienie już nie działa