I got this problem changing a color from a specific code. My problem is in jQuery, can someone help me out?
I would like to know if there's something I can do to change color from
selector. Something like this: when span
is :after / checkBox is checked ans then script run. .selector:after
will change border color that will show selector with a specific dynamically color using $(".selector").css("border", "solid " + "Red");
$(document).ready(function() {
});
.checkBox {
display: block;
position: relative;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* hide default checkBox */
.checkBox input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* create "checkbox" */
.selector {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background: #fff;
border-radius: 4px;
border-width: 1px;
box-shadow: inset 0px 0px 10px #ccc;
}
/* selector (hide it when checkBox not checked) */
.selector:after {
content: "";
position: absolute;
display: none;
}
/* show selector (when checkBox checked) */
.checkBox input:checked~.selector:after {
display: block;
}
/* selector style */
.checkBox .selector:after {
left: 9px;
top: 7px;
width: 5px;
height: 10px;
border: solid #1F4788;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label class="checkBox">
<input type="checkbox" value="x" name="x" id="x" />
<span class="selector"></span>
</label>
FIX/SOLUTION: I Did found the solution, thanks all for the Help: in CSS file:
.checkBox .selector:after {
left: 9px;
top: 7px;
width: 5px;
height: 10px;
border: solid;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
and in script JQuery on View add:
$(document).ready(function() {
$(".selector").css("color", "@ViewBag.vbColor");
});
ViewBag.vbColor, it will be a dynamic color coming from controller that acess a database table with specific colors. Thanks for all the help shared. :)