This code show the three buttons with check attribute.
I can change the color by clicking with :checked attribute in css.
However I want to change the color dynamically in javascript.
I can change the normal css by javascript but can I change :checked css???
$li = $(`<li><input type="checkbox" name="issueCheck" id="1"
value="1"><label for="1">1</label></li>`);
// I want to set the :checked background-color for this 'red'.
$('#issueCheckUl').append($li);
$li = $(`<li><input type="checkbox" name="issueCheck" id="2"
value="2"><label for="2">2</label></li>`);
// I want to set the :checked background-color for this 'red'.
$('#issueCheckUl').append($li);
$li = $(`<li><input type="checkbox" name="issueCheck" id="3"
value="3"><label for="3">3</label></li>`);
// I want to set the color here 'blue''
$('#issueCheckUl').append($li);
ul.ks-cboxtags {
list-style: none;
padding: 0px;
}
ul.ks-cboxtags li{
display: inline;
}
ul.ks-cboxtags li label{
display: inline-block;
background-color: rgba(255, 255, 255, .9);
border: 2px solid rgba(139, 139, 139, .3);
color: #adadad;
border-radius: 20px;
white-space: nowrap;
margin: 0px 0px;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
transition: all .2s;
}
ul.ks-cboxtags li label {
padding: 4px 8px;
cursor: pointer;
}
ul.ks-cboxtags li input[type="checkbox"]:checked + label {
border: 1px solid #1bdbf8;
background-color: #12bbd4; /* default color */
color: #fff;
transition: all .2s;
}
ul.ks-cboxtags li input[type="checkbox"] {
display: absolute;
}
ul.ks-cboxtags li input[type="checkbox"] {
position: absolute;
opacity: 0;
}
ul.ks-cboxtags li input[type="checkbox"]:focus + label {
border: 2px solid #e9a1ff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<ul class="ks-cboxtags" id="issueCheckUl"></ul>