I have used background color for checked checkbox through jQuery. My background color is adding only if i click any checkbox but not already clicked checkbox by default & i don't know why my class is not working on clicked checkbox by default.
$(document).ready(function() {
/*checkbox-background*/
$(".checkbox-primary").on("click", "input[type='checkbox']", function() {
if ($(this).is(":checked")) {
$(this).parent().addClass("fltr-chk-box-bg");
} else {
$(this).parent().removeClass("fltr-chk-box-bg");
}
});
/*checkbox-background-ends*/
});
.checkbox {
padding-left: 30px;
}
.checkbox>label {
display: inline-block;
position: relative;
padding-left: 5px;
color: #686868;
padding-top: 2px;
min-height: 25px;
font-family: 'montserrat';
}
.checkbox>span {
padding-right: 17px;
padding-top: 3px;
font-family: 'montserrat';
}
.checkbox input[type="checkbox"]:disabled+label::before {
background-color: #eeeeee;
cursor: not-allowed;
}
.checkbox.checkbox-circle label::before {
border-radius: 50%;
}
.checkbox.checkbox-inline {
margin-top: 0;
}
.fltr-chk-box-bg {
background-color: #E3E7EA;
color: #1E6C97;
}
.checkbox-primary input[type="checkbox"]:checked+label::before {
background-color: #1E6C97;
border-color: #428bca;
}
.checkbox-primary input[type="checkbox"]:checked+label::after {
color: #fff;
}
.checkbox input[type="checkbox"]:checked+label+span {
position: relative;
z-index: 75456;
}
.checkbox input[type="checkbox"]:checked+label+span:before {
content: '';
position: absolute;
top: 0;
right: 0;
border-bottom: 13px solid #CCD2D6;
border-top: 11px solid #CCD2D6;
border-right: 50px solid #CCD2D6;
border-left: 6px solid transparent;
z-index: -7523;
}
.fltr-panel-group {
margin-bottom: 0px;
}
.fltr-panel {
border-bottom: none;
}
.fltr-panel:last-child {
border-bottom: 1px solid #ddd;
}
.fltr-panel-title>a {
padding: 18px 8px 19px 8px;
font-size: 1.21em;
color: #2B3439;
font-family: 'montserrat';
}
.panel-group .panel+.panel.fltr-panel {
margin-top: 0px;
}
.panel-group.fltr-panel-group .panel-heading+.panel-collapse>.panel-body.fltr-panel-body {
border-top: none;
padding: 0px 5px 5px 5px;
}
.fltr-and-reset {
padding-top: 14px;
padding-bottom: 5px;
}
.fltr-and-reset a {
vertical-align: middle;
font-size: 0.78em;
}
.fltr-and-reset>.pull-right {
font-size: 1.07em;
color: #1E6C97;
font-family: 'montserrat';
}
.fltr-and-reset>.text-left {
font-size: 1.14em;
color: #302F2F;
line-height: 1.647;
font-family: 'montserrat';
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://ift.tt/2apRjw3">
<!-- jQuery library -->
<script src="http://ift.tt/2nYZfvi"></script>
<!-- Latest compiled JavaScript -->
<script src="http://ift.tt/2aHTozy"></script>
<form>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="" checked>
<label>North America</label><span class="pull-right">75</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="" checked>
<label>South America</label><span class="pull-right">98</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>North America</label><span class="pull-right">23</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South Asia</label><span class="pull-right">47</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South America</label><span class="pull-right">53</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>North America</label><span class="pull-right">55</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South America</label><span class="pull-right">26</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>North America</label><span class="pull-right">23</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South America</label><span class="pull-right">78</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South America</label><span class="pull-right">90</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>North America</label><span class="pull-right">67</span>
</div>
<div class="checkbox checkbox-primary">
<input type="checkbox" value="">
<label>South America</label><span class="pull-right">88</span>
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire